gpt4 book ai didi

c++ - 没有重载函数的实例 ""匹配参数列表错误

转载 作者:行者123 更新时间:2023-11-28 05:23:33 28 4
gpt4 key购买 nike

我的 cpp 中出现以下错误,我不太确定如何修复它们(我是 C++ 新手)

错误:

Severity    Code    Description Project File    Line    Suppression State
Error (active) no instance of overloaded function "std::basic_string<_Elem, _Traits, _Alloc>::compare [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" matches the argument list KernelHop c:\Users\Root\Downloads\KernelHop-master (1)\KernelHop-master\KernelHop\KernelHop.cpp 102


Severity Code Description Project File Line Suppression State
Error (active) no instance of overloaded function "std::basic_string<_Elem, _Traits, _Alloc>::compare [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" matches the argument list KernelHop c:\Users\Root\Downloads\KernelHop-master (1)\KernelHop-master\KernelHop\KernelHop.cpp 110

我的代码:

DWORD FindProcessId(const std::string processName)
{
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);

HANDLE processSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processSnapshot == INVALID_HANDLE_VALUE)
return 0;

Process32First(processSnapshot, &processInfo);
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processSnapshot);
return processInfo.th32ProcessID;
}

while (Process32Next(processSnapshot, &processInfo))
{
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processSnapshot);
return processInfo.th32ProcessID;
}
}

CloseHandle(processSnapshot);
return 0;
}

有人知道我做错了什么吗?

最佳答案

您可能正在编译为 Unicode,在这种情况下 PROCESSENTRY32::szExeFile 将是一个宽字符串 (wchar_t[]),但是 std::string::compare() 需要一个字节字符串 (char[])。所以尝试使用 std::wstring 代替。

关于c++ - 没有重载函数的实例 ""匹配参数列表错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40985619/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com