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
Post a Comment