Reputation: 658
I'm using a Japanese string as a wchar_t
, and I need to convert it to a char*
. Is there any method or function to convert wchar_t*
to char*
without losing data?
Upvotes: 2
Views: 1486
Reputation: 99993
You need to call WideCharToMultiByte
and pass in the code page encoding identifier for the Japanese multibyte encoding you want. See the MDSN for that function. On Windows, the local multibyte set is CP932, the MS variation on ShiftJIS. However, you might conceivably want UTF-8 to send to someone who wants it.
Upvotes: 2
Reputation: 437326
It is not enough to say "I have a string as wchar_t
". You must also know what encoding the characters of the string are in. This is probably UTF-16, but you need to know definitely.
It is also not enough to say "I want to convert to char
". Again, you must make a decision on what encoding the characters will be represented in. JIS? Shift-JIS? EUC? UTF-8? Another encoding?
If you know the answers to the two questions above, you can do the conversion without any problem using WideCharToMultiByte
.
Upvotes: 8