getline() and << operator returns stream.

I have read in some book that getline() << operator return stream.
What does this actually mean?.
By returning stream it means it returning the characters of stream
or something else.
Last edited on
It returns a reference to the stream that was passed as the first operand. It is what makes it possible to chain multiple calls to operator<< without having to repeat the stream object.

Example:

cout << "hello " << name; is the same as (cout << "hello ") << name;

First it calls cout << "hello " which will print "hello ". The return value of this expression is a reference to cout, so cout will be used as first argument to the second use of operator<< : cout << name;
Thanks alot.
Now. If i have a condition like this.
if(cin >> i){ }
How it will be evaluated to true or false.
Will you please explain the process.
Thanks alot.
Now. If i have a condition like this.
if(cin >> i){ }
How it will be evaluated to true or false.
Will you please explain the process.


operator >> returns a reference to the stream.

If the stream is valid (i.e. the correct data was given as input), an overloaded operator in std::istream returns a non-null pointer, which evaluates to true.

Otherwise if the stream is invalid, the overloaded operator returns a null pointer, which evaluates to false.

The overloaded operator in question here is operator void*().
Last edited on
Topic archived. No new replies allowed.