Load binary file using fstream

后端 未结 4 1918
遇见更好的自我
遇见更好的自我 2021-01-01 06:28

I\'m trying to load binary file using fstream in the following way:

#include 
#include 
#include 
#include         


        
4条回答
  •  青春惊慌失措
    2021-01-01 07:26

    The main question probably is what you mean by "binary file". The ios::binary only makes sure that the istream object doesn't replace platform-specific newlines by '\n'. Nothing else. Is that enough for you?

    An istream_iterator basically is just a fancy way to invoke operator>>. If you have real binary data in your stream, that will fail. Do you have real binary data in your file? Or are the integers stored as strings?

    If you need to read real binary integers, what you need is either istream.read() or using the stream buffer object directly.

提交回复
热议问题