解决 C++错误 error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no

今天在写程序编译的时候出现了如下的错误:

error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)
 

代码如下

void CBus::SetValue(CString strid,CString strruntime,CString stroriginstation,CString strterminalstation,CString strtotaltime,CString strmaxpeople,CString strnowpeople)
{

 strId = strid; 

 strRunTime = strruntime;
 strOriginStation = stroriginstation;
 strTerminalStation = strterminalstation;
 strTotalTime = strtotaltime;
 strMaxPeople = strmaxpeople; 

 strNowPeople = strnowpeople;

}

 

其中strid,strmaxpeople,strnowpeople对应数据库里面的列名,数据类型为int,在执行编译的时候就出现了三处上面提示的错误,分别是大括号里第一行和最后两行,几经周折终于发现了问题所在,原来是将整形的strid赋值给了字符型的strId,其他两个同样如此。

 

解决办法,用itoa()函数将整数转换为字符串(Convert an integer to a string)

 

 strId = atoi(strid); //将整形转换成字符串
 strMaxPeople = atoi(strmaxpeople); //将整形转换成字符串
 strNowPeople = atoi(strnowpeople); //将整形转换成字符串

再次编译就通过了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值