I'm doing on a win32 application, and has a edit control that accepts unicode text input. I use the following code to get the text to a std::string
:
WCHAR out[50] = {};
GetDlgItemTextW(hwnd, ID_Edit, out, 50);
wstring myWString(out);
string myString(ws.begin(), ws.end());
In the dubugger, I can see that myWString
is fine when input is unicode text, but myString
is currupted.
How can I convert it correctly?
EDIT:
OK, rather then fooling with string
, I use wstring
instead.
But another problem arise:
I have another code that was using string
, cout
and cin
to get user input in consle, now wstring
, wcin
and wcout
breaks the non-ASCII text input and out put part...
For my code it was:
string myString;
//...
cin >> myString;
//...
cout << myString;
Changing to:
wstring myString;
//...
wcin >> myString;
//...
wcout << myString;
The input and output text are corrupted if the user use non-ASCII characters.