在回答这个问题时,我遇到了这段代码......
#include <iostream>
int main()
{
int const income = 0;
std::cout << "I'm sorry your income is: " < income; // this is line 6
}
...其中包含一个错字。第 6 行的第二个(预期的)<<
运算符被意外写为<
.
除此之外,使用 GCC 4.3.4或 4.4.3 编译代码会导致警告:
prog.cpp: In function ‘int main()’:
prog.cpp:6: warning: right-hand operand of comma has no effect
我的问题:为什么会产生那个特别的警告?它指的是哪个逗号运算符?
注意:我并不是提倡<
在cout
声明中故意使用单个。 我只是在试图找出我链接到的另一个问题的答案时偶然发现了这个警告,并且很好奇编译器为什么会生成它。