Incompatible with parameter of type quot;LPCWSTRquot;(与类型“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.
设置项目->属性 ->高级(或旧版本的通用)->用于使用多字节字符集
另见截图
这篇关于与类型“LPCWSTR"的参数不兼容;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:与类型“LPCWSTR"的参数不兼容;
基础教程推荐
- c++ STL设置差异 2022-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
