c++ - When using cout and cin, what are the "<<" and ">>" operators doing and why do we use them? -


for example:

int age; cin >> age;  cout << "you " << age << " years old!" << endl; 

why use "<<" , ">>" operators here? doing? understand bit-shifting, don't how works here.

they called stream insertion operator (<<) , stream extraction operator (>>).

these same operators left , right bit shift operators (even though have different names). bit shift operators overloaded, when left side stream, read or write stream.

they're function call - works like:

leftshift(leftshift(leftshift(leftshift(cout, "you "), age), " years old!"), endl); 

except function called operator<< instead of leftshift.
strictly speaking, there's no reason function called leftshift has left shift, , likewise there's no reason function called operator<< has left shift.


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -