endl 不会在输出文件中创建新行
endl not creating new line in output file
这是我现在的代码
#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++ 有两种类型的文件:文本和二进制。二进制文件不是文本。它们没有行,所以它们没有行尾。如果您想明智地谈论行尾和其他与文本相关的事情,请使用文本文件。
相关文章:
- 使用新行和不使用新行读取文件
- 遇到新行时,有没有办法停止istream_iterator
- C++:继续创建新的变量可以吗
- C++ 如何在将新对象分配给另一个对象时创建新对象
- PangoLayout 中忽略的新行
- 重用对象与创建新对象
- C++,创建新对象时类的对象更改
- 使用 clang 格式时,当行很大时,如何将右括号分成新行?
- 如何检测将文本文件读入 int 数组的新行
- 当 getline 直到新行才读取时会发生什么?
- 如何在新数组较小时创建新数组并将旧数组的最后一个元素复制到新数组中?
- 添加新行时工作代码引发异常.调试技巧?
- QTree查看新行,没有布局就不可见已更改
- 新行上的 clang 格式右括号
- 从文件中读取多行.txt字符串删除空格并创建新文件进行输出
- endl 不会在输出文件中创建新行
- 试图创建csv,输出不断将数据放在新行上
- 复制另一个文件时,在新文件中创建新行
- 创建新的visual studio项目,添加文件并运行它-命令行
- 如何在不创建新行的情况下使用cin输入变量