读书人

关于switch的一个简单的有关问题

发布时间: 2012-03-19 22:03:05 作者: rapoo

关于switch的一个简单的问题
switch(m_strReceiveString)
{
case '0D':
{
..
break;
}
case 'F9':
{
.....
break;
}
.
.
}
这里m_strReceiveString是CString类的,提示说出错了,switch expression of type 'class CString' is illegal
我该怎么改正呢?

[解决办法]
The condition shall be of integral type, enumeration type, or of a class type for which a single conversion
function to integral or enumeration type exists (12.3). If the condition is of class type, the condition is converted
by calling that conversion function, and the result of the conversion is used in place of the original
condition for the remainder of this section.
[解决办法]
所以改成if语句吧。然后将CString转换成字符串,然后用strcmp比较
[解决办法]
switch(xxx) 这里xxx不可以为CString类型
[解决办法]
switch()里面只能是产生整型结果的表达式
[解决办法]
字符串不能直接比较的
显然就不对了

读书人网 >C++

热点推荐