I have a 2-dimensional array of doubles and I would like to output those numbers to a file (each second dimension is a line). That's not a problem. The problem is that the output numbers are saved in a txt file with different degree of precision. Example:
0 1.173 1.3 2.0744 0 0.13
But I would like them to be like:
0.0000 1.1730 1.3000 2.0744 0.0000 0.1300
I have tried std::setprecision(6)
and std::cout.precision(6)
but they don't seem to work on this, or maybe I use them in the wrong way. Here it is a simplified version of how I output data to a file:
std::ofstream ofile("document.dat");
for(int i = 0; i < array_size; i++) {
ofile << array[i][0] << " " array[i][1] << std::endl;
}