Questions about streams

Hello,
I reciently started streams. I have a couple of questions, When you use

cout.setf(ios::scientific | ios::showpos):

Why does the output use both of these flags when your using an or indicator?

Why am I supposto precede the setf() function with cout?

Thanks again for taking a look.

enduser000
The flags are just bit patterns, eg 00000001 and 00000010, so you can use OR to combine them and AND to test for them. It's a fairly common technique for setting flag values. In decimal the flags will have values 1,2,4,8,16... so you can use a single int to hold a number of them.

There is a load of documentiaon on basic streams at http://www.cplusplus.com/reference/iostream/, as you will see there are a number of ways of setting things.

setf() is actualy a method of the class istream1, which cout is a member of, which is why you need cout.setf()

You can also use cout << scientific << showpos to do the same thing.



[1] Or to be more exact, a member of ios_base which is inherited by istream.
Do a google for "truth tables". This should give you a good rundown on bitwise OR, XOR and AND operators.
Topic archived. No new replies allowed.