istream_iterator to iterate through bytes in a binary file

后端 未结 2 1026
攒了一身酷
攒了一身酷 2021-01-13 11:48

Given a file containing the following hex code: 0B 00 00 00 00 00 20 41

I\'m trying to populate an std::vector and then check

2条回答
  •  感动是毒
    2021-01-13 12:23

    istream_iterator should not be used for reading binary files. It uses operator>>, which is also not suited for reading binary files (unless those files are of a very specific format which most binary files do not fit). You can use istreambuf_iterator instead. You also want to be sure to open your file in binary mode.

    in.open("filepath", std::ios::in | std::ios::binary);
    

提交回复
热议问题