std::string == not working?

std::string == not working?

本文关键字:working not std string      更新时间:2023-10-16

当我这样做时:

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)

如何解决此错误?

感谢

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

#include <string>

这通常是因为编译器需要查看包含文件中的字符串类的定义,以验证它是否确实声明了一个接受char*

的运算符

您可能缺少

#include <string>

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