VS2010错误error C2678

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前用的好好的,今天整理了一下工程,删除了一些没用到的.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语言的字符串类



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值