二进制表达式的操作数无效(&#39; std :: ostream&#39;(又名&#39; basic_ostream <char>&#39;)和&#39; const char *&#39;)

时间:2016-01-30 22:12:20

标签: c++ c++11 clang

当尝试使用Cheerp(使用clang ++)编译我的c ++代码时,我从终端获得此输出:

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

这是我对终端的命令:

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

以下是它遇到问题的代码:

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

1 个答案:

答案 0 :(得分:15)

FIXED ::我忘了#include <iostream>