I have programmed some code but there is some problem. In this codes i am trying to convert string to wstring. But this string have "█" characters. This character have 219 ascii code. This conversion getting error.
In my code:
string strs= "█and█something else";
wstring wstr(strs.begin(),strs.end());
After debugging, I am getting result like this
?and?something else
How do I correct this problem?
Thanks...
The C-library solution for converting between the system's narrow and wide encoding use the
mbsrtowcs
andwcsrtombs
functions from the<cwchar>
header. I've spelt this out in this answer.In C++11, you can use the
wstring_convert
template instantiated with a suitablecodecvt
facet. Unfortunately this requires some custom rigging, which is spelt out on the cppreference page.I've adapted it here into a self-contained example which converts a
wstring
to astring
, converting from the system's wide into the system's narrow encoding: