小编Thi*_*Thi的帖子

c ++ operator <<(char)但输出但是在hexa/int中

为什么三个运算符<<输出不同的方式?

#include <iostream>
#include <string>

using namespace std;

int main()
{
  operator<<(cout, "Hello").operator<<('w').operator<<(endl); // Hello119

  cout << (void *)'w' << endl; // 0x77

  cout << 'w'; // w

  operator<<(operator<<(cout, "Hello"), 'w').operator<<(endl); // Hellow !!!
}
Run Code Online (Sandbox Code Playgroud)

第一个带有2个参数的运算符<<按预期为字符串提供正确的输出,而其他参数则不...

有人可以向我解释一下吗?


更多信息:

cout << "Hello" << 'w' << endl; 会被解释为......

operator<<(operator<<(cout, "Hello"), 'w').operator<<(endl); // Hellow

c++ operator-overloading ostream

2
推荐指数
1
解决办法
53
查看次数

标签 统计

c++ ×1

operator-overloading ×1

ostream ×1