invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'const char *')
29,448
FIXED:: I just forgot to #include <iostream>
Related videos on Youtube
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, 2022Comments
-
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 about 8 yearsI guess your standard library headers are corrupted.
-
Jonathan Allen Grant about 8 years@Lingxi how can I fix them?
-
Lingxi about 8 yearsJust 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 about 4 yearsActually it might be just
#include <ostream>