I use the following code to read current directory in Windows 7. The current directory is C:\特斯塔敌人. The current locale is English(EN). I used getCurrentDirectoryW with the idea that it will properly read the directory path since the function is using unicode:
wchar_t w_pcRootLocation[MAX_PATH+100];
GetCurrentDirectoryW(MAX_PATH, w_pcRootLocation);
wcout << w_pcRootLocation << endl;
MAX_PATH is defined in WinDef.h and is equal to 260.
When I print the output to the console using wcout, what I see is only the following:
C:\
The Chinese characters are not read apparently. What is the issue here and how do I read the path in Unicode properly?
Thanks.
GetCurrentDirectoryW() is likely working fine. It’s the next bit that’s got problems.
std::wcout is going to use the “C” locale. You’re going to need to adjust (
imbue()) it appropriately to display your out of codepage glyphs. See this SO question for details.