In this Stack Overflow answer
it says that std::cout << "Hello World!" << std::endl;
is the same as
std::operator<<(std::operator<<(std::cout, "Hello World!"), std::endl);
But when I compile the above line code, it doesn't compile! Then after trying something else I found that the reason it doesn't compile is because of std::endl
, if I replace std::endl
by "\n"
then it works. But why you can not pass std::endl
to std::operator<<
?
Or more simply, isn't std::cout<<std::endl;
the same as std::operator<<(std::cout, std::endl);
?
EDIT
When compile with icpc test.cpp
, the error message is
error: no instance of overloaded function "std::operator<<" matches the argument list argument types are: (std::ostream, <unknown-type>) std::operator<<(std::cout, std::endl);
and g++ test.cpp
gives much much longer error message.