之前用的好好的,今天整理了一下工程,删除了一些没用到的.h和.cpp文件,重新编译,发生错误:
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
代码定位在if语句里:
string filetype = tmp.substr(pos+1, tmp.length()-pos);
//strupr() c
transform(filetype.begin(), filetype.end(), filetype.begin(), toupper); //C++提供的字母小写转大写
char node[64] = {0};
if (filetype == "JPG" || filetype == "BMP" || filetype == "PNG" || filetype == "DIB" ||
filetype == "JPEG" || filetype == "JPE" || filetype == "GIF" ||
filetype == "TIF" || filetype == "TIFF" || filetype == "JFIF")
{
strcpy_s(node, "PIC_FILE_CONFIG");
}
filetype == "JPG" || filetype == "BMP" || filetype == "PNG" || filetype == "DIB"
添加了#include <string.h>,问题依旧。
添加#include <string>,问题解决。
string是c++字符串标准库类,string.h是c语言的字符串类

本文介绍了一位开发者在C++项目中遇到的字符串比较错误C2678,并分享了解决过程。通过分析代码发现,问题在于使用了C风格字符串处理头文件而非C++标准库。最终通过引入正确的<string>头文件解决了该问题。

被折叠的 条评论
为什么被折叠?



