• Register
100 points
7 2
Welcome to Kodlogs, programming questions and answer website.

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.

100 points
7 2