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

While left shift operator (<<) using before std::cout , what does it work for?

本文关键字:lt 什么 左移 运算符 std cout      更新时间:2023-10-16

那些代码行:

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()之前)?

您似乎在第一个语句结束时似乎缺少半隆,而且您正在重复std::cout

您需要使用

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

之类的变体
std::cout << "a" << std::cout<< "b";

std名称空间中输出对象cout地址,格式为十六进制,在字符串" A"answers" B"之间。