Does std::cout have a return value?

后端 未结 3 1485
傲寒
傲寒 2020-12-01 14:57

I am curious if std::cout has a return value, because when I do this:

cout << cout << \"\";

some hexa code is printed. What\'s

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-01 15:57

    cout does not have a return value. cout is an object of type ostream. operator << has a return value, it returns a reference to cout.

    See http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/ for reference.

    The only signature that matches is:

    ostream& operator<< (ostream& ( *pf )(ostream&));

    so it returns the pointer to the operator<< member.

    the one in James' answer. :)

提交回复
热议问题