i hav manage to create a file and read it..
the << system("grep text file");>> is it just add in like this?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// Create a file and write the inputs into the file.
// If the file is already exist, then write the data at the end of the file so that the
// existing data is not overwriten.
// Save the file before exit.
ofstream myFile;
myFile.open("CityFile.txt",ios::app|ios::out);
myFile<<"This file contains the cities name."<<endl<<endl;
myFile<<"Singapore"<<endl;
myFile<<"Bangkok"<<endl;
myFile<<"Phnom Penh"<<endl;
myFile.close();
// Open the file which is saved and display the data in the file.
string line;
ifstream Myfile("cityFile.txt");
if(Myfile.is_open())
{
while(!Myfile.eof())
{
getline(Myfile,line);
cout<<line<<endl;
}
Myfile.close();
}
else
cout<<"Unable to open this file."<<endl;
system("grep text file");
system("Pause");
return 0;
}