Getting desired binary data ranges from std::istreambuf_iterator and std::ifstream

前端 未结 2 767
感动是毒
感动是毒 2020-12-22 03:47
#include 
#include 
#include 
#include 

int main()
{
    std::ifstream file(\"data.bin\", std::ios::bin         


        
2条回答
  •  自闭症患者
    2020-12-22 04:38

    The class std::istreambuf_iterator iterates over the characters extracted from a std::basic_istream> or, actually, its std::basic_streambuf>. That is, given a specific stream type, there is no choice for the std::istreambuf_iterator. Also note that the IOStream layer is not intended to operate on binary files, despite the std::ios_base::binary operation which is passed to the stream buffers.

    If you want to extract shorts (or any other type than the stream's character type) you'd need to create a suitable iterator yourself which takes the chosen binary format the file was written in into account. This iterator can be built in terms of std::istreambuf_iterator or directly access the std::streambuf.

提交回复
热议问题