#include <iostream> // header std::cout << "Hello world!" << std::endl;
Works so because
std::cout is an
std::ostream type object managing console output.
And, thankfully, somewhere in the
C++ standard, we have something defined like this:
std::ostream& operator<< (std::ostream&, const char * );
The first argument and the return type of the function is
This makes it possible to have something like:
std::cout << "Hello world!" << " How you doing?" << " Bye" << std::endl;
This is no biggie and seems pretty basic. But, what made me fell in love with C++ all over again is this:
What if we have a function like:
void Print (std::ostream& os);
either as a member function or a standalone function.
Then, of course,
Print (std::cout); Print (std::cerr); Print (std::cout << "Haha -- "); Print (std::cout << "Answer to everything=" << 42);
All are valid, working calls. Which for some probably insignificant reason, I find extremely amazing.