简体   繁体   中英

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

Those code lines:

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

Generate the compiler error below:

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

Could anyone please tell me what left shift operator( << ) is doing on there (before std::cout << pobserverIndex -> observerInt() )?

You appear to be missing a semicolon at the end of your first statement, plus you are repeating std::cout .

You need to use

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

A variant like

std::cout << "a" << std::cout<< "b";

is outputting the address of the object cout in the std namespace, formatted as hexadecimal, between the strings "a" and "b".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM