android - How to convert ASCII char* to wchar_t* in C++ without using mbstowcs? -


i'd convert ascii char* wchar_t* in c++ on linux without using mbstowcs(). on ios , windows, works perfectly. on android, however, mbstowcs seems convert things quite literally, one-to-one. using different variations of setlocale(), i've been unable convert.

i might end manually converting on android copying 1 byte, , filling rest zeroes. proper ascii? first 255 characters of utf-32/unicode same ascii (iso 8859-1/iso latin-1) character set?

if don't mind taking stl dependency , using string , wstring instead of raw char * , wchar_t * pointers, can use function following perform string conversions:

template<typename target, typename source> target convertstring(const source &s) {     target result;     result.assign(s.begin(), s.end());     return result; } 

use follows:

#include <string> #include <iostream> using namespace std;  int main() {     wstring wstr(l"hello world");     string str(convertstring<string, wstring>(wstr));     cout << str << endl;     return 0; } 

this performs character-by-character conversion , platform-independent. has been tested on windows using gcc 4.7.3 , visual c++ 2012 on linux using gcc 4.7.3.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -