• Register
1,240 points
15 11 8

Symbols that can perform operations on values or variables are known as operators. For example +, -, =, %, << etc. Cout operator (<<) is used to print the output to the screen. Operands are the values or the variable on which operators perform operations. Every operator has its own function/task. Sometimes the wrong operator can cause errors.

Error

No operator “<<” matches these operands C++

Cause

Availability of the definitions in header files may cause this error. Some definitions are available in one header file but the operator is not available in that header file.

#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;
}

Here, we have a string in the presence of header file iostream. Unfortunately iostream contains the definitions for the string but it does not contain << operator.

Solution

To resolve this error you have to add an extra header file called #include <string>. This header file contains all the definitions and the operator related to the strings.

Hope this will help.

More Posts

No operator matches these operands C++ Lalit Kumar - Apr 22, 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
Indirection Requires Pointer Operand ('Int' Invalid) in C++ Lalit Kumar - Sep 6, 2020
Error : no match for operator = Lalit Kumar - Jul 15, 2020
How to compare strings in C++? Lalit Kumar - Jun 14, 2020
What Does -> Mean in C++? Lalit Kumar - Sep 6, 2020
delete v/s delete[] in C++ Lalit Kumar - Aug 11, 2020
Indirection Requires Pointer Operand Lalit Kumar - Sep 9, 2020
uniform_int_distribution in c++ Lalit Kumar - Jul 6, 2020