[英]no instance of overloaded function “” matches the argument list error
I'm Getting the following errors in my cpp and I'm not quite sure how to fix them (I'm new to C++) 我在cpp中遇到以下错误,但我不确定如何解决(我是C ++的新手)
Errors: 错误:
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
My Code: 我的代码:
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;
}
Anyone know what I'm doing wrong? 有人知道我在做什么错吗?
You are probably compiling as Unicode, in which case PROCESSENTRY32::szExeFile
will be a wide string ( wchar_t[]
), but std::string::compare()
expects a byte string ( char[]
). 您可能正在使用Unicode进行编译,在这种情况下,
PROCESSENTRY32::szExeFile
将是一个宽字符串( wchar_t[]
),但std::string::compare()
需要一个字节字符串( char[]
)。 So try using std::wstring
instead. 因此,请尝试使用
std::wstring
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.