C++ 向文件写入16进制


接收short,将其分成两个char写入文件
void WriteU16(std::ostream& file, short val)
{
    char bytes[2];
 
    // extract the individual bytes from our value
    bytes[0] = (val) & 0xFF;  // low byte
    bytes[1] = (val >> 8) & 0xFF;  // high byte
 
                                   // write those bytes to the file
    file.write((char*)bytes, 2);
}

 




posted @ 2016-06-01 08:16  elninovt9  阅读(1637)  评论(0编辑  收藏  举报