更新时间:2023-02-11 07:55:19
ASCII中的数字10"是换行字符\n
.在C ++中,这是换行符.
The "number 10" in ASCII is the line feed character, \n
. In C++, this is the newline character.
您显然已将文件作为文本流打开.因为换行符在不同平台上的表示方式不同,所以文本流执行换行符翻译:在读取时,它们将平台特定的换行符表示转换为\n
;在编写时,它们将\n
字符转换为平台特定的换行符表示.
You have apparently opened the file as a text stream. Because newlines are represented differently on different platforms, text streams perform newline translation: when reading they translate the platform-specific newline representation into \n
and when writing they translate the \n
character into the platform-specific newline representation.
在Windows上,换行符由\r\n
表示.当您向文本流中写入\n
时,它将被写入为\r\n
.
On Windows, line breaks are represented by \r\n
. When you write a \n
to the text stream, it gets written as \r\n
.
要写入原始二进制数据,需要将流作为二进制流打开.这是通过将ios_base::binary
标志传递到流的构造函数来完成的.
To write raw binary data, you need to open the stream as a binary stream. This is done by passing the ios_base::binary
flag to the constructor of the stream.