switch语句,刚知道还有这个说法..................
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
cin> > a;
switch(a)
{
case "wo ":break;
default:break;
}
return 0;
}
报错:
E:\学习\程序\token\token.cpp(164) : error C2450: switch expression of type 'class std::basic_string <char,struct std::char_traits <char> ,class std::allocator <char> > ' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
switch(这里竟不能用string类型????),郁闷, 这下if语句可有得写了
有办法解决没有,还得用string,还想用switch。。。。。
把string强制转换成char*!
[解决办法]
这里竟不能用string类型????),
===================================
是的。。
[解决办法]
不行,switch case 对应的是常量,
char* 也不行,
单个字符可以,如 'c '
[解决办法]
字符串不行