Учу WinApi, задали написать файловый менеджер.
#include "pch.h"
#include <iostream>
#include <windows.h>
#include <string>
#include <fstream>
using namespace std;
int main()
{
HANDLE hFindFile, hFile;
WIN32_FIND_DATA fd, file_inf[100];
int i, counter;
counter = 0;
string comand, directory, prev, file_name, user_path, addition[100];
directory = "D:\\";
prev = "D:\\";
bool x = true;
i = 0;
while (true) {
cout << "help to see all comands" << endl;
cin >> comand;
if (comand == "help") {
cout << "dir - show all files in current directory" << endl;
cout << "cd - enter directory" << endl;
cout << "kill - delete file" << endl;
cout << "text - create file" << endl;
cout << "copy - copy file" << endl;
}
if (comand == "dir") {
cout << "_____________" << endl;
hFindFile = FindFirstFile ((directory + "*.*").c_str(), &fd);
file_inf[0] = fd;
while (FindNextFile(hFindFile, &fd)) {
i++;
file_inf[i] = fd;
}
int n = i;
for (i = 0; i <= n - 1; i++) {
cout << file_inf[i].cFileName << endl;
}
cout << "_____________" << endl;
i = 0;
}
if (comand == "cd") {
cout << "directory name?" << endl;
cin >> addition[counter];
if (addition[counter] == "..") {
counter--;
directory = prev;
}
else {
counter++;
}
for (int i = 0; i < counter; i++) {
directory += "\\" + addition[i] + "\\";
}
cout << directory << endl;
}
if (comand == "kill") {
cout << "file's name?" << endl;
cin >> file_name;
hFindFile = FindFirstFile((directory + file_name + "*.*").c_str(), &fd);
file_inf[0] = fd;
cout << directory + file_name << endl;
DeleteFile((directory + file_inf[0].cFileName).c_str());
}
if (comand == "create") {
cout << "file's name?" << endl;
cin >> file_name;
hFile = CreateFile((directory + file_name).c_str(),
GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hFile);
}
if (comand == "copy") {
cout << "file's name?" << endl;
cin >> file_name;
cout << "new folder?" << endl;
cin >> user_path;
CopyFile((directory + file_name).c_str(), (user_path + file_name).c_str(), false);
}
}
system("pause");
return 0;
}
Выдает 4 ошибки по типу: C2664 "HANDLE FindFirstFileW(LPCWSTR,LPWIN32_FIND_DATAW)": невозможно преобразовать аргумент 1 из "const _Elem *" в "LPCWSTR". Подскажите как быть?