What is the difference ?

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>
using namespace 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';
}
You mean you came upon this code?
http://www.cplusplus.com/reference/iomanip/setprecision/

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).
Topic archived. No new replies allowed.