读文件
char buffer[256];
ifstream in("words.txt");
if (!in.is_open())
{ cout << "Error opening file"; exit (1); }
while (!in.eof())
{
in.getline(buffer,100);
cout << buffer << "1"<< endl;
if( in.good() ) //这句话防止被再读一次
{
break;
}
}
in.close();
写文件
ofstream outfile;
outfile.open("words.txt");
cout<<"writing: "<<s<<endl;
outfile<<s<<endl;
outfile.close();