c++文件问题
来源:百度知道 编辑:UC知道 时间:2024/06/01 04:20:00
使用的是c++的文件处理 #include<fstream.h> 如何向文件中输入换行
补充:input<<'\n'和input<<'\r\n'都没有用
补充:input<<'\n'和input<<'\r\n'都没有用
"\r\n"和endl都可以换行,不信可以运行下面的程序看看。
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str = "Hello\r\nWorld\r\nHello World!";
ofstream test("temp.txt");
test<<str;
test << endl << "This is a test!";
test.close();
return 0;
}
ofstream fout("abc.txt");
fout<<endl;
一楼说的对,直接用<<endl就行了。
不是 '\n' 是 "\n"