从 cplusplus.com,我看到ostream该类的成员函数operator<<如下所示:
ostream& operator<< (bool val); ostream& operator<< (int val);
.... 等等。
这确实有意义,因为当您像 cout<<x 激活ostream& operator<< (int val) 函数一样使用 Cout 对象时,您实际上是<<在 Cout 对象上使用运算符。这与所有其他运算符非常相似,并将int变量发送到函数。当我想流式传输自己的对象时,有什么区别以及究竟会发生什么?为什么语法是突然的ostream& operator<< (**ostream &os**, object ob)?为什么我需要添加 ostreamvar?我还在用 cout<<ob,这不就是 ostream& operator<< (object obj)为什么吗?我通过的只是我的对象。对象已经在cout那里了。