Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

This question seems to have solved the issue for wcout...

wcout not writing wide character out to command prompt

It's worth checking with a debugger to make sure w_pcRootLocation does contain the characters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top