由于我不能使用字符串作为switch语句的参数,我应该使用什么?

时间:2017-10-04 22:04:40

标签: c++ string switch-statement

由于switch语句不接受字符串,因此我应该使用除switch语句之外的语句。有什么我可以使用的,不会要求我写出大量的if语句吗?或者有没有办法让switch语句采用字符串?我需要另一种方法而不是switch语句,所以我可以检查多个(> 20)不同的情况。

vector<string> tokens;
string present;
while(....){
string right_value = right->evaluate();  <-- finds out what the string to the right of present is 
string left_value = left->evaluate();   <-- finds out what the string to the left of present is. 
switch(present){
 case "write" : return right_value;
.
.
.
.
.
}

0 个答案:

没有答案