Writing binary to std::fstream using the << operator

前端 未结 2 938
忘了有多久
忘了有多久 2020-12-07 02:52

For some reason this sort code is not working as I would expect:

std::fstream theFile;
theFile.open(, std::ios::beg |std::ios::out|std::i         


        
2条回答
  •  醉梦人生
    2020-12-07 03:11

    You need to typecast the values first as a char, otherwise the iostream library sees the values as int and formats them as a readable string.

    theFile << (char)1 << (char)25;
    

提交回复
热议问题