逗号运算符如何在C ++中使用cout?

时间:2018-04-25 15:57:00

标签: c++ debugging

的返回值(未打印)是什么
cout << 1, 2, 3, 4, 5;

如何调试此代码?

我需要解释ostream和cout的工作原理。

1 个答案:

答案 0 :(得分:0)

返回值为int,其值为5。作为副作用,将打印1

#include <iostream>

using namespace std;

int main(void)
{
    auto rv = (cout << 1, 2, 3, 4, 5);

    std::cout << rv;

    return 0;
}