Error: no operator "==" matches these operands

Anes

This isn't actually my code, but I need help right here. Since I'm new to coding, I don't know how to fix this problem.

bool GetProcessEntryByName(string name, PROCESSENTRY32* pe) {
    auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (snapshot == INVALID_HANDLE_VALUE) {
        cerr << "Tool helper cannot be created" << endl;
        return false;
    }

    if (!Process32First(snapshot, pe)) {
        cerr << "Tool helper cannot retrieve the first entry of process list" << endl;
        return false;
    }

    do {
        if (pe->szExeFile == name) {
            snapshot ? CloseHandle(snapshot) : 0;
            return true;
        }
    } while (Process32Next(snapshot, pe));

    snapshot ? CloseHandle(snapshot) : 0;
    return false;
}

And the error occurs at: if (pe->szExeFile == name)....

Output:

1>------ Rebuild All started: Project: EzExecV2, Configuration: Debug x64 ------
1>main.cpp
1>E:\Desktop\Coding\Test\main.cpp(45,28): error C2678: binary '==': no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\shared\guiddef.h(192,15): message : could be 'bool operator ==(const GUID &,const GUID &)'
1>D:\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\random(2056,24): message : or       'bool std::operator ==(const std::bernoulli_distribution &,const std::bernoulli_distribution &)'
1>E:\Desktop\Coding\Test\main.cpp(45,28): message : or       'built-in C++ operator==(WCHAR [260], WCHAR [260])'
1>E:\Desktop\Coding\Test\main.cpp(45,28): message : while trying to match the argument list '(std::string, WCHAR [260])'
1>E:\Desktop\Coding\Test\main.cpp(106,24): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(106,9): warning C4309: 'argument': truncation of constant value
1>E:\Desktop\Coding\Test\main.cpp(111,27): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(111,9): warning C4309: 'argument': truncation of constant value
1>E:\Desktop\Coding\Test\main.cpp(133,23): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(133,9): warning C4309: 'argument': truncation of constant value
1>E:\Desktop\Coding\Test\main.cpp(137,24): warning C4305: 'argument': truncation from '__int64' to 'DWORD'
1>E:\Desktop\Coding\Test\main.cpp(137,9): warning C4309: 'argument': truncation of constant value
1>Done building project "Test.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

I'm using Unicode Char Set

I don't know if there is a more detailed log for the build. If there is, tell me where I can find it.

vll

You are compiling the project with Unicode, so Process32FirstW() will be called instead of Process32First(). Change your function to take wstring as parameter or convert name to wstring before comparison:

std::wstring wName(name.begin(), name.end());
if (pe->szExeFile == wName) {

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

IntelliSense: no operator "<<" matches these operands

C++ - no operator "<<" matches these operands directory_iterator()

error: no operator "<" matches these operands

C++ - Error - No operator "[]" matches these operands

Error during implementation of operator>> :C++ no operator matches these operands operand types are: std::istream >> const double error

more than one operator "[]" matches these operands

No operator "<<" matches these operands - C++

C++) E0349 no operator matches these operands occured

no operator ">>" matches these operands -- operand types are: std::istream >> const double

Accessing an entry in std::map causes 'no operator "[]" matches these operands'

No operator "<" matches these operands operand types are: double < my_class

no operator ""<<"" matches these operands error

Error : no operator " != " matches these operands

no operator ">>" matches these operands operand types are: std::istream >> double*

No operator "+" matches these operands, aka cannot add Array<double> to double

No Operator = Matches Operands - DX11

no operator matches these operands; operand types are: std::istream >> const char [5]

E0349 no operator ">>" matches these operands

C++ No operator [] matches these operands

No operator ">=" matches these operands error in c++ when using while loop

no operator "=" matches these operands error

No Operator ">>" matches these operands operand types are: std::istream>>int

"no operator >> matches these operands"

No operator "<<" matches these operands error between an object and a string literal

no operator "<<" matches these operands recursive tower of hanoi error

No operator "[ ]" matches these operands C++

no operator "/" matches these operands

Error C++: no operator matches these operands. operand types are: std::ostream << void

E0349 no operator "<<" matches these operands