I have a totally basic C++ question here.
#include <iostream>
using namespace std;
int main() {
int a = 255;
cout << hex << a << endl; // <-----
}
In the code piece above, how is the std::cout
statement chained?
I understand that an implementation of cout
would return the reference to cout
object to allow chaining to happen, so it should be executed as:
(((cout << hex) << a) << endl)
i.e. equivalent to these, in order
cout << hex
cout << a
cout << endl
But this cannot be the case because somehow value of a
needs to be converted to hex
form!
How are operators actually chained by the compiler to make the conversion happen?