reading fortran binary file in c++

后端 未结 2 372
再見小時候
再見小時候 2021-01-24 00:29

The problem of reading (with c++ program) binary file generated by fortran code has been asked many times and the satisfactory description of conventions in fortran records has

2条回答
  •  隐瞒了意图╮
    2021-01-24 01:19

    operator>> is the formatted input operator. It is used to read text files, converting the textual representation to binary.

    You should be reading using unformatted input operations. Try this:

    file.read(reinterpret_cast(&ival), sizeof ival);
    

    Of course, after you read it, you may need to byte swap for correct endian representation.

提交回复
热议问题