i have a file and two inputs are shown below:
34.800287000 0.077352000
i’m reading from a file(by getline then define stringstream) and saving it in my class variables which are both defined double. However
when i check my variables i see that:
34.8003 0.077352
EDIT: i’m using cout to check my variables.
why is that ?
thanks.
The standard IO streams classes have a limit to their precision that can be customized at runtime. By default I believe it’s six places, which matches the output you’re getting above. If you want to increase the precision, you can use the
setprecisionstream manipulator:The
setprecisionmanipulator is defined in<iomanip>and when used once will change the behavior ofcoutto print at higher precision for the rest of the program, which in your case may be helpful. Try this out and see if your numbers really are losing precision.