c++写入文件的时候怎么可以一行一行的写入

2025-02-28 14:25:48
推荐回答(5个)
回答1:

#include
#include
#include
using namespace std;
void main()
{
//读取1.txt全部内容
ifstream ifs("1.txt");//如果需要,请修改文件路径
if(!ifs)
{
cout<<"文件打开失败!";
return;
}
char ch[100];
while (!ifs.eof())
{
ifs.getline(ch,100);
cout<}
ofstream ofs("2.txt");
outstuf>>number.c_str()>>" ">>"写入的内容">>endl;
}

回答2:

outstuf.write(number.c_str(),number.length());
改为
outstuf>>number.c_str()>>" ">>"语文">>endl;//endl就是换行

回答3:

\n 这个是换行符 输出换行符就可以了

回答4:

使用函数 sprintf(“\n”)

回答5:

<