What are and ?
In functions like cout, cin, and the stringstream functions, they aren't just your average function() functions, but they use << and >> instead of parenthesis. Could someone explain what that's all about?
Your question belongs in For Beginners.
They are operators; in the same class of "thing" as +, / etc. They take a stream on the left hand side and some other type on the right hand side. The evaluation of the operator, generally, inputs or outputs the RHS from/to the stream *as a side effect*, and evaluates to a reference to the left hand side (the object may have changed its state as a result of the process, but the "same object" is returned).
They are operators; in the same class of "thing" as +, / etc. They take a stream on the left hand side and some other type on the right hand side. The evaluation of the operator, generally, inputs or outputs the RHS from/to the stream *as a side effect*, and evaluates to a reference to the left hand side (the object may have changed its state as a result of the process, but the "same object" is returned).
They aren't functions at all, they are objects. Specifically stream objects in the STL library. cin and cout are default defined to system input and output. The objects have overloaded the '<<' and '>>' operators to do the same as 'printf()' and 'scanf()', just in a safer friendlier way.
std::cin is a global variable of type std::istream
std::cout is a global variable of type std::ostream
They aren't functions, they are objects, and thus support operator overloading: << and >> have been overloaded to work with them.
When you write std::cout << 42;, you are really doing operator<<(std::cout, 42);, which ends up calling std::ostream& std::operator<<(std::ostream&, const long& );
std::cout is a global variable of type std::ostream
They aren't functions, they are objects, and thus support operator overloading: << and >> have been overloaded to work with them.
When you write std::cout << 42;, you are really doing operator<<(std::cout, 42);, which ends up calling std::ostream& std::operator<<(std::ostream&, const long& );
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement