相关疑难解决方法(0)

为什么这段代码会产生一个引用逗号运算符的警告?

在回答这个问题时,我遇到了这个代码......

#include <iostream>

int main()
{
    int const income = 0;
    std::cout << "I'm sorry your income is: " < income;    // this is line 6
}
Run Code Online (Sandbox Code Playgroud)

...其中包含拼写错误.第<<6行的第二个(预期)操作符被意外写为a <.

除此之外,使用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
Run Code Online (Sandbox Code Playgroud)

我的问题:为什么会产生特别警告?它指的是哪个逗号运算符?

注意:我并不是主张<cout声明中故意使用单曲. 我只是偶然发现了这个警告,同时试图找出我已经链接到的另一个问题的答案,并且好奇为什么编译器会生成它.

c++ cout comma-operator

8
推荐指数
1
解决办法
3310
查看次数

标签 统计

c++ ×1

comma-operator ×1

cout ×1