I've been trying to learn C++ by reading a book I bought off amazon.com (I have beginner experience in Java then decided to switch to C++ as my 1st language). The book I'm reading tells me to type the following to get cout to display a certain amount of sig figs:
are supposed to do. I was able to get the same result just typing the following:
1 2 3 4
double a = 44.8765;
cout << fixed;
cout.precision(2);
cout << a << endl;
So what was the point of typing out all that stuff in the 1st example? Basically I'm having trouble understanding what .setf and ios::xxxx are supposed to do.
They are flags; values set to either on or off, and the state of them affects the output. If the flag is already set to on, and then you set it to on, it will make no difference. The best way to see what they all do is to experiment with them.