std :: string ==不工作?

时间:2011-06-03 00:18:03

标签: c++ visual-studio

当我这样做时:

std::string name = targetBone->getName();
    if(name == "Pelvis")
    {
        return;
    }

我明白了:

Error 1 error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

如何解决此错误?

由于

2 个答案:

答案 0 :(得分:6)

您是否在cpp文件中包含了字符串

#include <string>

这通常是因为编译器需要查看驻留在该包含文件中的字符串类的定义,以验证它确实声明了一个带有 char * 的运算符

答案 1 :(得分:0)

你可能错过了

#include <string>

此外,为了比较字符串,您应该使用strcmp()内置函数,而不是仅使用运算符。