ofstream

来源:百度知道 编辑:UC知道 时间:2024/06/06 12:48:50
我想写个程序把 用ofstream
把1写到 1.txt上,

#include <fstream>

....

ofstream ofs("1.txt");
if( ofs.fail() )
{
return false;
}
ofs<<"1"<<endl; //这里把1当字符串了。
ofs.close();

也可以int a = 1;
ofs<<a;不要忘了关闭文件哦。