C++ binary file I/O to/from containers (other than char *) using STL algorithms

前端 未结 4 520
逝去的感伤
逝去的感伤 2021-01-06 22:52

I\'m attempting a simple test of binary file I/O using the STL copy algorithm to copy data to/from containers and a binary file. See below:

 1 #include 

        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 23:39

    For the question 1) You need to specify a separator (for example a space). The non-decimal part was stuck to the decimal part of the previous number. Casting and using NULL is generally wrong in C++. Should have been a hint ;)

    copy (vd.begin(), vd.end(), oi_t(output, " ")); 
    

    For the question 2)

    #include 
    output << setprecision(9);
    

提交回复
热议问题