I see that it is allowed to write a char to a std::wostream (for example, std::wcout<<"looooool";).
How are the char changed to wchar (if that’s what happens)?
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.
When you send a
charor a c-string (char *) to a wide stream, the ìndividual octets (bytes) are converted to wchar withwiden. There is no automatic conversion from astd::string.You cannot send multibyte UTF-8 characters into a wide stream this way, because the bytes are converted one at a time. In the default locale, there is no conversion from a non-ascii character to a wide character, so the conversion will fail, putting the wide stream into error state.
Whether you take advantage of this conversion or not is up to you; the standard allows it, and for character and string literals, at least, it seems harmless to me. But do be aware that string objects you send to a wide stream must be
std::wstring, notstd::string.