Source: http://www.daniweb.com/software-development/cpp/threads/155420
C++ Syntax (Toggle Plain Text)
bool cvtLPW2stdstring(std::string& s, const LPWSTR pw, UINT codepage = CP_ACP) { bool res = false; char* p = 0; int bsz; bsz = WideCharToMultiByte(codepage, 0, pw,-1, 0,0, 0,0); if (bsz > 0) { p = new char[bsz]; int rc = WideCharToMultiByte(codepage, 0, pw,-1, p,bsz, 0,0); if (rc != 0) { p[bsz-1] = 0; s = p; res = true; } } delete [] p; return res; } int main() { wchar_t msg[] = L"Hello, world!"; std::string s("\?"); cvtLPW2stdstring(s,msg); std::cout << s << std::endl; return 0; }
No comments:
Post a Comment