endl 不会在输出文件中创建新行

endl not creating new line in output file

本文关键字:创建 新行 文件 输出 endl      更新时间:2023-10-16

这是我现在的代码

#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
// set up input file
ifstream lInput;    // declare an input file variable (object)
ofstream lOutput;
lInput.open(argv[1], ifstream::binary); // open an input file (binary)
lOutput.open(argv[2], ofstream::binary);
if (!lInput.good())
{
    // operation failed
    cerr << "Cannot open input file " << argv[1] << endl;
    return 2;       // program failed (input)
}
lOutput << "test" << endl;
lOutput << "test2" << endl;

我当前的输出是

测试测试2

我该如何做到

测试

测试2

感谢您的帮助

编辑:测试到"测试",测试2

到"测试2"edit2: lOutpt to lOutput

C 和

C++ 有两种类型的文件:文本二进制。二进制文件不是文本。它们没有行,所以它们没有行尾。如果您想明智地谈论行尾和其他与文本相关的事情,请使用文本文件。