c++ - VS2017 fstream.write() always outputs an extra 0x0d in the middle?
天蓬老师
天蓬老师 2017-05-16 13:27:22
0
1
1186
#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 6660
a90d 0ac8 
  ||________多了一个0x0d

VS2017,Win10SDK,Win7 x64 system
Release x86(Win32)
Please advise, what is going on? Is it a case or a BUG?

Supplement: It seems that when the number of output bytes is greater than or equal to 19, an extra 0x0d will be output in the middle, and there will be no problem if the output is less than 19 bytes

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
洪涛

Please use ios::binary to read and write binary files.

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!