search

Home  >  Q&A  >  body text

c++ - ostringstream的二进制输出问题

std::ostringstream curBuf(std::ios::binary);
curBuf.write((char*)HEAD_DATA,sizeof(HEAD_DATA));

这是一段png加密代码中的一小部分,HEAD_DATA被定义为常量(unsigned char[])类型,储存png头的信息。然而我将curBuf转存值文件后,发现其中多了1个bit"0x0d",十分诡异。然而直接输出至ofstream就不会有这个问题。

PHP中文网PHP中文网2803 days ago626

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 13:26:58

    0x0d character encoding is carriage return
    write is an unformatted input and output, carriage return is not omitted
    Direct output to ofstream is a formatted input and output, carriage return is omitted

    reply
    0
  • Cancelreply