I'm came upon a code but having removing one line changes the whole output of the program. However I couldn't figure out the reason why. In the code below having the "cout<<fixed;" removed cause a different output. Why is that ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <iomanip>
usingnamespace std;
int main ()
{
double f =3.14159;
cout << setprecision(5)<<f<<'\n';
cout << setprecision(9)<<f<<'\n';
cout << fixed;
cout << setprecision(5)<<f<<'\n';
cout << setprecision(9)<<f<<'\n';
}
Cite your references, not just "I found some code...".
> In the code below having the "cout<<fixed;" removed cause a different output. Why is that ?
Because fixed has a side effect.
You'd get a different output if you removed any other cout statement as well. I'm not sure what you're expecting to see, or what sort of answer you want (short of RTFM).