在 Windows 中使用 DevC++ 和在 Ubuntu 中使用 gcc 写入文件有什么区别

What's the difference with writing in files using DevC++ in Windows and on gcc in Ubuntu

当我在 Windows 上使用 DevC++ 编译器和在 Ubuntu 上使用 GCC 编译器写入文件时,我发现了这种奇怪的差异。对于代码和输入文件,当我在 DevC++ 上生成输出文件时,它的大小是 432Bytes。但是当相同的代码是 运行 相同的输入时,它会生成 351Bytes 的输出文件。 (请注意右下角的文件大小。)

但我发现文字没有什么不同。检查 link 以获得 diff output.txt out_test.txt 的输出。 谁能解释一下为什么会这样?

那是因为您 write/read 您的文件处于文本模式而不是 ios::binary 模式。

每有一个换行符,一个换行字节写在ubuntu上,而有两个字节写在windows上(回车return + 换行符)。当行尾有空格时,也可能存在一些差异。