return value of cout and cin
the << and >> operators of cout and cin return references to cout and cin, which is why you can chain the << and >> operators.
In other words
cout << 1 << "test";
becomes
cout.operator<<(1).operator<<("test");
And since cout.ooperator<< returns a reference to cout after printing the first value it effectively becomes
cout.operator<<("test");
And after that prints, it returns a reference to cout which isn't used for anything (the most common use of the returned reference, that I'm aware of is for writing overloaded operator<< and >> functions for printing and reading your own classes).
In other words
cout << 1 << "test";
becomes
cout.operator<<(1).operator<<("test");
And since cout.ooperator<< returns a reference to cout after printing the first value it effectively becomes
cout.operator<<("test");
And after that prints, it returns a reference to cout which isn't used for anything (the most common use of the returned reference, that I'm aware of is for writing overloaded operator<< and >> functions for printing and reading your own classes).
cin and cout are objects - they don't have return values. However, they have a lot of methods and overloaded operators that returns something. If you want to know what these methods returns to you - look it up:
http://www.cppreference.com/cppio/index.html
http://msdn2.microsoft.com/en-us/library/zae2h4f4(vs.80).aspx
http://www.cppreference.com/cppio/index.html
http://msdn2.microsoft.com/en-us/library/zae2h4f4(vs.80).aspx
Quote:Original post by TEUTON
So, basically references to themselves.
When using the << and >> operators on them then yes those functions do.
As Paulius Maruska said cout and cin are objects which don't have return values. I just assumed your were talking about the << and >> operators in particular.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement