I am wondering if std::endl works with both std::cout and std::wcout?
Anyone is clear on this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. In fact,
std::endlis a function template that will work as a manipulator on any specialization of thestd::basic_ostreamtemplate.Some more detail: 27.7.3.6 prescribes that the
std::basic_ostreamtemplate contain overload foroperator<<as follows:The effect of invoking this overload on a suitable function is
return pf(*this). So when you saystd::cout << std::endl, this actually becomesstd::endl(std::cout)and returns a reference to the stream object.All other ostream manipulators are written in the same way, and similarly for input manipulators.
The magic of the
endlfunction template is a call towiden('\n'), which produces the correct "newline" data for the given character type.