1

这是我现在的代码

#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”编辑2:lOutpt到lOutput

4

1 回答 1

3

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

于 2017-03-28T11:50:02.200 回答