C++ writing and reading doubles from a binary file

前端 未结 4 1124
春和景丽
春和景丽 2021-01-06 04:45

I want to perform disk I/O operations for a program that takes too much RAM. I use matrices of doubles and think writing them to disk as bytes is the fastest way (I need to

4条回答
  •  臣服心动
    2021-01-06 05:17

    How to do it with portability?

    There are different definitions/levels of portability. If all you ever do is to write these on one machine and read it on the same one, the only portability you are concerned with is whether this code is well-defined. (It is.)
    If you want to write portably across several different platforms, you need to write string values, rather than binary ones.

    However, note that the code you have lacks proper error handling. It doesn't check whether the file could be opened and successfully written to.

提交回复
热议问题