虽然左移位运算符(<<)在std :: cout之前使用,但它有什么作用?

时间:2017-09-08 07:06:19

标签: c++ c++11 error-handling compiler-errors bitwise-operators

那些代码行:

std::cout << "observerIndex : " <<
std::cout << pobserverIndex -> observerInt() ;

在下面生成编译器错误:

file.C:2917:37: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'std::basic_ostream<char>')
     std::cout << "observerIndex : " <<
                                     ^

有人可以告诉我左移操作员(<<)在那里做什么(std::cout << pobserverIndex -> observerInt()之前)?

1 个答案:

答案 0 :(得分:0)

您在第一个语句结尾处似乎缺少分号,而且您正在重复std::cout

您需要使用

std::cout << "observerIndex: " << pobserverIndex -> observerInt(); 

这样的变体
std::cout << "a" << std::cout<< "b";

在字符串“a”和“b”之间输出格式为十六进制的cout命名空间中的对象std地址