0 points
15 11 8

No operator matches these operands

Problem and Cause

Today we are going to discuss the error “no operator matches these operands”. The cause behind these errors is common but the error isn’t. This error is caused by the availability of definitions in header files. Just think you’re lucky enough that some definitions are available in one header file but the operator is not available in this header file. Now we have enough talk let’s jump to an example.

#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>
#include <cctype>

using namespace std;

int main()
    vector<string> words; //some random string
        while (used.find(guess) != string::npos)

    return 0;

Code explained with cause

Here we have a string and we know that we can define any string without any problem in C++ program in the presence of #include<iostream> header file because <iostream> has many definitions for strings but unfortunately, it doesn’t have << operator.

How to resolve it?

As we discussed the cause of the error. so, I’m assuming that you understood about the error and now you are able to resolve it. But I cannot leave it here like this. I have to give a solution. So, if you want to resolve this error then you have to add another header file which is #include<string> because it consists of the operator which was missing in for our program.
If you have any other problems, let us know by dropping your problem in the comment section.

More Posts

No operator << matches these operands C++ Lalit Kumar - Sep 15, 2020
Error : no match for operator = Lalit Kumar - Jul 15, 2020
lvalue required as left operand of assignment c++ Lalit Kumar - Apr 17, 2020
How to compare strings in C++? Lalit Kumar - Jun 14, 2020
no operator found which takes a right-hand operand of type Lalit Kumar - Aug 14, 2020
operator overloading in c++ using friend function Lalit Kumar - Oct 14, 2020
Error "no rule to make target" in C++ Lalit Kumar - Jul 12, 2020
Indirection Requires Pointer Operand ('Int' Invalid) in C++ Lalit Kumar - Sep 6, 2020
Unary operator in C++ Yogesh Sharma - Aug 1
fatal error: iostream: no such file or directory Lalit Kumar - Jul 7, 2020