My program reads text from a file and puts it in combo box.
When the file contains text with english characters everything works fine.
When it contains some polish letters, they are replacing with strange characters.
The file encoding is UTF-8 (without BOM).
myCombo = CreateWindowExW(WS_EX_CLIENTEDGE, (LPCWSTR)L"COMBOBOX", NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
a, b, c, d,
hwnd, (HMENU)ID_COMBO, hThisInstance, NULL);
wstring foo;
wifstream bar("theTextFile.txt");
getline(bar, foo);
SendMessageW(myCombo, CB_ADDSTRING, (WPARAM)0, (LPARAM)(foo.c_str()));
What can I do to make my program showing correct national letters?
PS. Sorry for my poor English 🙂
wifstreamwon’t read UTF-8 text on Windows by default. Thecodecvtfacet in the stream’s locale is what converts from the bytes in the file intowchar_t, so you need to set this such that it will do the conversion towchar_tyou want.Something like this: