C++如何将结果保存到txt文件中
1个回答
展开全部
你可以直接把内容写到txt文件中啊,比如下面的代码里面,就是把内容写到out.txt文件里
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream out("out.txt");
if (out.is_open())
{
out << "This is a line.\n";
out << "This is another line.\n";
out.close();
}
return 0;
}
//结果: 在out.txt中写入:
//This is a line.
//This is another line
// writing on a text file
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
ofstream out("out.txt");
if (out.is_open())
{
out << "This is a line.\n";
out << "This is another line.\n";
out.close();
}
return 0;
}
//结果: 在out.txt中写入:
//This is a line.
//This is another line
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询