发布网友
共1个回答
热心网友
ofstream outfile("目标文件名.txt",ios::in); //打开文件
if(!outfile)
{
cerr<<"open 目标文件名.txt error!\n"; //文件不存在就报错
return 0;
}
cin>> x;
outfile<<x<<endl;
outfile.close(); //关闭文件