How to read from the console LPCWSTR?

There is a task:
In the console to enter the directory. Print the names of all txt files in the directory .

Visual Studio 2012.
For one course to install the Boost is not desirable. So is winapi.
How to get the list of files I found, but to correctly enter the directory from the console
and read it can't. FindFirstFile requires as file path, LPCWSTR,
and to introduce a line of this type of console does not work.
Tell me what to do or give referring to Hyde, where it is shown.
July 8th 19 at 16:44
3 answers
July 8th 19 at 16:46
If on pure WinAPI, you have to first get the encoding of console (GetConsoleCP) (in Russian Windows it is usually 866 or 1251), to read the line in the regular PSTR, and then convert to PWSTR using WideCharToMultiByte. The encoding of the console you need to send it to WideCharToMultiByte.
wcin - doing it all himself.
Add: in the WinAPI usually, all functions have ANSI and Unicode variants. And the key is Unicode and ANSI version converts input parameters to Unicode and calls the Unicode version.
FindFistrFile is usually a #define macro defined in "windows.h", depending on the settings of the project this macro determines the use of either ANSI version or Unicode version of the function.
ANSI and Unicode versions of the same function differ by a suffix in the name: FindFistrFileA - ANSI version FindFistrFileW - Unicode.
No one will interfere in your code to force it to use the ANSI version of the function. So it is possible to eliminate the need to convert the string. - Lucio commented on July 8th 19 at 16:49
July 8th 19 at 16:48
LPCWSTR is const wchar_t*
Read to use wcin, or wscanf.
July 8th 19 at 16:50

Find more questions by tags WindowsC++