myhrra myhrra - 2 months ago 18
C++ Question

How to set precision of output file?

ofstream coord("C:\\coordinates.txt");
(for loop starts here)
(things happen here)
coord << i << "," << result[i].X << "," << result[i].Y << ",0\n";
(for loop ends here)
coord.close();


In the output file I'm having coordinates exponential like this:

12,4.49999e+06,3.5e+06,0


How can I get rid of those exponential parts? I tried to put a "fixed" after "coord<<" in the line below but it didn't work.

coord << i << "," << result[i].X << "," << result[i].Y << ",0\n";

Answer

Use std::fixed

std::cout << std::fixed << result[i].X