与类型“LPCWSTR"的参数不兼容;
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <dos.h>
using namespace std;
class Dir
{
public:
char* cat;
Dir()
{
cout << "(C:/*)
";
cat = new char[50];
cin >> cat;
}
void virtual ShowFiles()
{
}
};
class Inside : public Dir
{
public:
void virtual ShowFiles()
{
HANDLE hSearch;
WIN32_FIND_DATA pFileData;
hSearch = FindFirstFile(cat, &pFileData);
if (hSearch != INVALID_HANDLE_VALUE)
do
{
// if ((pFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
cout << pFileData.cFileName << "
";
} while (FindNextFile(hSearch, &pFileData));
FindClose(hSearch);
}
};
int main()
{
Dir *obj1[2];
obj1[1] = new Inside;
obj1[1]->ShowFiles();
return 0;
}
所以我有一个程序,我需要用动态字符 cat 显示目录中的所有文件,但它可以在 Borland C++ 中编译,但在 Visual Studio 15 + Resharper 中它不起作用.严重性代码描述项目文件行char *"类型的错误(活动)参数与LPCWSTR"类型的参数不兼容
So I have a program, I need to show with dynamic char cat all file in directory, but it is compilable in Borland C++ but in Visual Studio 15 + Resharper it doesn't work. Severity Code Description Project File Line Error (active) argument of type "char *" is incompatible with parameter of type "LPCWSTR"
推荐答案
要在 Visual C++ 中编译代码,您需要使用多字节字符 WinAPI 函数而不是宽字符函数.
To compile your code in Visual C++ you need to use Multi-Byte char WinAPI functions instead of Wide char ones.
设置项目->属性 ->高级(或旧版本的通用)->用于使用多字节字符集
另见截图
相关文章