c++ - VS2017 fstream.write() 总是在中间多一个输出一个0x0d ?

浏览:37日期:2023-03-20

问题描述

#include 'stdafx.h'using namespace std;int main() { ofstream out('out.dat'); char ss[19] = { 0x78, 0x9c , 0xe3 , 0x62 , 0x60 , 0xe0, 0x62 , 0x60 , 0xf5 , 0x49 , 0x2d , 0x4b , 0xcd, 0x61 , 0x66, 0x60 , 0xa9 , 0x0a , 0xc8 }; out.seekp(0); out.write(ss, 19); return 0;}输出: 20个字节789c e362 60e0 6260 f549 2d4b cd61 6660a90d 0ac8 ||________多了一个0x0d

VS2017,Win10SDK,Win7 x64系统Release x86(Win32)求教,这是怎么回事?是个案还是BUG?

补充: 好像当输出的字节数大于等于19时,就会在中间多输出一个0x0d,而小于19个字节的输出就不会出问题

问题解答

回答1:

二进制文件读写请使用ios::binary。

ofstream out('out.dat', ios::binary);

c++ - VS2017 fstream.write() 总是在中间多一个输出一个0x0d ?

相关文章: