1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
wstring s2ws(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
int main()
{
string str="йаᠭ1";
wstring wstr=s2ws(str.c_str());
LPCWSTR s=wstr.c_str();
char str[8];
size_t sizeRequired;
ZeroMemory(str, 8);
sizeRequired = WideCharToMultiByte( CP_UTF8, 0, s, 1, str, 4, NULL, NULL);
std::cout << "The letter : " << str << endl;
std::cout <<"The size: "<< sizeRequired << endl;
return 0;
}
|