如何将字符串输入作为开关盒参数?我可以用int
而不是字符串。如何使用switch case取一个字符串参数?
如果我使用的是int
输入,下面的代码会工作,但如果我更改为字符串,它将无法工作。
#include <iostream>
#include <sstream>
#include <string>
#include <math.h>
class MissionPlan //start of MissionPlan class
{
public:
MissionPlan();
float computeCivIndex(string,int,int,float,float);
}; //end of MissionPlan class
LocationData::LocationData()
{
switch(sunType)
{
case "Type A": //compute
break;
case "Type B": //compute
break;
//and many more case..
default: break;
}
}
int main()
{
for(;;)
{
MissionPlan plan;
}
return 0;
}
我都没有超过12年感动C++,但我敢肯定你不能。 – jahroy