Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ append unsigned char to wstring

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);
like image 283
tmighty Avatar asked Dec 06 '22 08:12

tmighty


1 Answers

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));
like image 82
Joachim Isaksson Avatar answered Dec 09 '22 14:12

Joachim Isaksson