std :: string ==不工作?

jma*_*erx 2 c++ visual-studio

当我做:

std::string name = targetBone->getName();
    if(name == "Pelvis")
    {
        return;
    }
Run Code Online (Sandbox Code Playgroud)

我明白了:

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

我该如何解决这个错误?

谢谢

par*_*mar 6

你有没有在你的cpp文件中包含字符串

#include <string>
Run Code Online (Sandbox Code Playgroud)

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