Why can we use the manipulators in <iomanip>

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Why can we use the manipulators in <iomanip>

Post by ImLazy »

It is said the manipulators in the header <iomanip> can be used in the operator <<, such as:

Code: Select all

cout << setbase(16) << 100 << endl;
But when I read the manual of the header <iomanip>, here, I found none of the manipulators receives argument of type ios_base. So I can't understand which overload of operator << in class ostream, here, do these manipulators match.
Who can tell me? Thanks.[/url]
Last edited by ImLazy on Thu Jun 28, 2007 12:11 pm, edited 1 time in total.
I stay home. Don't call me out.

Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

The second (manipulators that do not take arguments) and third (manipulators that take an argument).

It's clearly said in the manual you pointed to that manipulators return unspecified types that operator<< and operator>> are overloaded for, so you shouldn't be expecting any of these operators to be overloaded for ios_base.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

ImLazy
Experienced poster
Posts: 215
Joined: Sat Jul 10, 2004 4:31 pm
Location: Shanghai, China

Post by ImLazy »

Oh, I see. The manipulators in <iomanip> don't use the overloads of operator << in <ostream>, but the overloads defined in <iomanip> which are not visible for us. Am I right?
I stay home. Don't call me out.

Krzysztof Duleba
Guru
Posts: 584
Joined: Thu Jun 19, 2003 3:48 am
Location: Sanok, Poland
Contact:

Post by Krzysztof Duleba »

Yes, instructions like cout << setw(5) are evaluated so that setw(5) returns an object of implementation-specific class, for which appropriate overloads are provided in iomanip header.
For millions of years, mankind lived just like the animals. Then something happened which unleashed the power of our imagination. We learned to talk and we learned to listen...

Post Reply

Return to “C++”