invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'const char *')

29,448

FIXED:: I just forgot to #include <iostream>

Share:
29,448

Related videos on Youtube

Jonathan Allen Grant
Author by

Jonathan Allen Grant

I used to travel around the United States, living in my Toyota Prius, going to hackathons every weekend. Now I work at Two Sigma.

Updated on August 05, 2022

Comments

  • Jonathan Allen Grant
    Jonathan Allen Grant over 1 year

    When trying to compile my c++ code with Cheerp (using clang++), I get this output from my terminal:

    example.cpp:102:9: error: invalid operands to binary expression ('std::ostream'
          (aka 'basic_ostream<char>') and 'const char *')
        out << "(" << loc.x << ", " << loc.y << ")";
        ~~~ ^  ~~~
    

    Here is my command to the terminal:

    /opt/cheerp/bin/clang++ -target cheerp example.cpp -o example.js
    

    And Here is the code it has trouble with:

    static std::ostream& operator <<(std::ostream & out, const CornerLoc &loc)
    {
        out << "(" << loc.x << ", " << loc.y << ")";
        if (loc.type == kCorner)
            out<<"-corner";
        if (loc.type == kCornerNorthWest)
            out<<"-cornerNW";
        if (loc.type == kCornerNorthEast)
            out<<"-cornerNE";
        if (loc.type == kCornerSouthWest)
            out<<"-cornerSW";
        if (loc.type == kCornerSouthEast)
            out<<"-cornerSE";
        return out;
    }
    
    • Lingxi
      Lingxi about 8 years
      I guess your standard library headers are corrupted.
    • Jonathan Allen Grant
      Jonathan Allen Grant about 8 years
      @Lingxi how can I fix them?
    • Lingxi
      Lingxi about 8 years
      Just a guess. I'm not sure. Try compile the code in question on an online compiler (e.g., Wandbox) and see whether the problem remains.
  • Ivan Baidakou
    Ivan Baidakou about 4 years
    Actually it might be just #include <ostream>