c++向文本文件写入字符串

2024-11-28 16:53:07
推荐回答(2个)
回答1:

#include
#include
#include
using namespace std;
int main()
{

ofstream outdata;
outdata.open("bool.txt",ios::app);//ios::app是尾部追加的意思
outdata<<"其实我没有测试过。。。"<outdata.close();
return 0;
}

回答2:

ofstream file;
file.open( "a.txt", ios::out );
string str = "dddddddddddddddfbbbbbbbbb";
if ( file.is_open() )
{
file << str << endl;
}
file.close();

方法很多!