The variable filepath
which is a string
contains the value Música
. I have the following code:
wstring fp(filepath.length(), L' ');
copy(filepath.begin(), filepath.end(), fp.begin());
fp
then contains the value M?sica
. How do I convert filepath
to fp
without losing the encoding for the ú character?
Since you are using MFC, you have access to the ATL String Conversion Macros.
This greatly simplifies the conversion vs. using
MultiByteToWideChar
. Assuming thatfilepath
is encoded in your system's default code page, this should do the trick:If
filepath
is not in your system's default code page (let's say it's in UTF-8), then you can specify the encoding to convert from:To convert the other way, from
std::wstring
tostd::string
, you would do this:Use the function MultiByteToWideChar.
Sample code: