为什么三个运算符<<输出不同的方式?
#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