C++ append unsigned char to wstring

append, c++, wstring

Solution

The correct call for appending a char to a string (or in this case, a wchar_t to a wstring) is

sDebug.push_back(SomeValue);

Documentation here.

To widen your char to a wchar_t, you can also use std::btowc which will widen according to your current locale.

sDebug.push_back(std::btowc(SomeValue));

Problem

I want to append an unsigned char to a wstring for debugging reasons. However, I don't find a function to convert the unsigned char to a wstring, so I can not append it. Edit: The solutions posted so far do not really do what I need. I want to convert 0 to "0". The solutions so far convert 0 to a 0 character, but not to a "0" string. Can anybody help? Thank you. ``` unsigned char SomeValue; wstring sDebug; sDebug.append(SomeValue); ```

Original source