V
V
Vladislav2016-06-05 13:38:12
C++ / C#
Vladislav, 2016-06-05 13:38:12

How to read from console LPCWSTR?

There is a task:

Enter the directory in the console. Print the names of all txt files in the .

Visual Studio 2012.
For the sake of one coursework, I don’t want to install Boost. Means remains winapi.
I found how to get a list of files, but I can’t correctly enter the directory from the console
and can’t read it. FindFirstFile requires an LPCWSTR as the path to the file,
and you can't enter a string of this type from the console.
Tell me what to do or give a link to a guide where it is shown.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2016-06-05
@Hateman31

If on pure WinAPI, then you must first get the console encoding (GetConsoleCP) (in Russian Windows it is usually 866 or 1251), read the string into a regular PSTR, and then convert it to PWSTR using WideCharToMultiByte. The console encoding is needed to pass it to WideCharToMultiByte.
wcin does it all by itself.

A
Alexander Taratin, 2016-06-05
@Taraflex

wcin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question