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
You could set the precision using setprecision
as Tristram pointed out, and do you need a delimiter. See the cppreference to see how the operator=
functions. There is no format set, so you will need to set it on output:
ofstream output ("temp.bin", ios::binary);
output.flags(ios_base::fixed); //or output << fixed;
copy(vd.begin(), vd.end(), oi_t(output, " "));
output.close();
I would tend to favor using fixed
to eliminate precision problems. There have been many cases were someone thought "we'll never need more than 5 digits" so they hardcoded a precision everywhere. Those are costly bugs to have to correct.