Write a program that inputs the name of five cities , stores in a file and read the contents of file and display on screen.

#include<iostream>
#include<fstream.h>
#include<stdlib.h>
using namespace std;
int main()
{
char city[50];
ofstream file(“D:\\city.txt”);
ifstream in(“D:\\city.txt”);
for(int i=0;i<5;i++)
{
cout<<“Enter the name of any city: “<<endl;
cin>>city;
file<<city<<endl;
}
file.close();
system(“cls”); // this function is used for clear screen
system(“color 61″); // it is used for change the color
cout<<“\nWelcome to www.candcpp.com and www.candcpp.net: \n”;
cout<<“\n\n”;
system(“pause”);
system(“cls”);
cout<<“The city names are: “<<endl;
for(int i=0;i<5;i++)
{
in>>city;
cout<<city<<endl;
}
system(“pause”);
return 0;
}

 

<—–End—–>

<——-output——–>

Enter the name of any city:

Lahore

Enter the name of any city:

Faisalabad

Enter the name of any city:

Islamabad

Enter the name of any city:

Karachi

Enter the name of any city:

Gujrat

welcome to www.candcpp.com and www.candcpp.net:

press any key to continue

The city names are

Lahore

Faisalabad

Islamabad

Karachi

Gujrat