#include <iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
ofstream ofile("test.txt",ios::app);
if(!ofile.fail())
{
cout<<"start write"<<endl;
ofile<<"Mary";
ofile<<"girl";
ofile<<"20";
}
else
cout<<"can not open";
return 0;
}
这里的要点是 ofstream ofile("test.txt",ios::app);
ios::app 追加模式打开文件夹, 以ios::app打开,如果没有文件,那么生成空文件;如果有文件,那么在文件尾 追加。