문제

How do you convert an std::string encoded in extended ascii to utf8 using microsoft visual studio 2005?

I'm using google protocol buffer and it's complaining about non utf8 characters in my string if I give it without conversion, which is true...

도움이 되었습니까?

해결책

Use MultiByteToWideChar to convert your string to UTF-16, then use WideCharToMultiByte to convert it to UTF-8.

다른 팁

Let's assume that mysterious Exntended ASCII is just Latin1. Then use mask from wikipedia:

110y yyxx 10xx xxxx

Since you have only 00..FF then you have: 1100 00xx 10xx xxxx.

Conversion algorithm will be following, if char code is < 127 then just dump it as is, if it is > 127 then you do 0xC0 | ((x & 0xC0) >> 24) goes to first byte, second is ((x & 0x3F) | 0x80)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top