您的位置:首页 > 其它

文件读写 fstream

2016-12-26 09:57 148 查看
读文件

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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: