DEV Community

Lalit Kumar
Lalit Kumar

Posted on

no operator found which takes a right-hand operand of type

The binary error occurs when the programmer forgets to include a string which is a sequence of characters, variables, or symbols. When a string is not used, the compiler indirectly imports parts of a string into its iostream which renders the process unreliable. The iostream can also break because the operator lacks strings to implement the algorithm. An operator is a symbol that tells the compiler to perform a specific mathematical function or a logical operation. There are different operators in the C++ programming language:


title: "no operator found which takes a right-hand operand of type"
tags: cpp

canonical_url: https://kodlogs.com/blog/1923/no-operator-found-which-takes-a-right-hand-operand-of-type

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Bitwise operators
  • Assignment operators
  • Misc operators

More info

A programmer is always supposed to include and specify the operator in the syntax for a program else the error of no operator found.

Another reason you can get such an error is that the operator is overloaded, which results in user codes behaving abnormally. Sometimes when there is a mismatch or the rules of operators are not observed between the left-hand and right-hand operands, similar errors occur and user codes cannot run.

The basic concept when using operators is that they should be assigned and defined to a class and the former should have a copy of the constructor and an assignment operator defined.

Illustration;
`
Point :: Point (const Point&);

and

Point& Point :: operator= (const Point &);
`

Example

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
    string title = "THE WORLD OF PIRATES";
    cout << title << endl;
    cout << " Welcome to the world of pirates";

    cin.get();

    return 0;
}
Enter fullscreen mode Exit fullscreen mode

Error is defined as

binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Enter fullscreen mode Exit fullscreen mode

Solution

Here we forget to #include

std::string can work without including header file in some compilers because they directly import parts of . They can also break when we try to output the string since they only include a part of the implementation and the operator Β« was missing from the implementation.

Hope this helps.

Top comments (0)