字符串与switch

由于switch后面判断需要的只能是整数,字符串不行,那如何解决呢??

       string key = .....来自文本。。。。
        string parameters[] = {
            "default_filename", "http_proxy", "no_proxy", "strip_cgi_parameters", "save_state_internal", 
            "connection_timeout", "reconnect_delay", "num_connections", "buffer_size", "max_speed",
            "verbose", "alternate_output"
        };
        for (int i = 0; i <= 11; i++) {
            if (key == parameters[i]) {//key是从文本中获得的
            	switch (i) {
            	case 0:
            		conf_object.default_filename = value;
            		break;
            	case 1:
            		conf_object.http_proxy = value;
            		break;
            	case 2:
            		conf_object.no_proxy = value;
            		break;
            	case 3:
            		conf_object.strip_cgi_parameters = atoi(value.c_str());
            		break;
            	case 4:
            		conf_object.save_state_internal = atoi(value.c_str());
            		break;
            	case 5:
            		conf_object.connection_timeout = atoi(value.c_str());
            		break;
            	case 6:
            		conf_object.reconnect_delay = atoi(value.c_str());
            		break;
            	case 7:
            		conf_object.num_connections = atoi(value.c_str());
            		break;
            	case 8:
            		conf_object.buffer_size = atoi(value.c_str());
            		break;
            	case 9:
            		conf_object.max_speed = atoi(value.c_str());
            		break;
            	case 10:
            		conf_object.verbose = atoi(value.c_str());
            		break;
            	case 11:
            		conf_object.alternate_output = atoi(value.c_str());
            		break;
            	default:
            		cout << "the parameters from loadfile has no matched" << endl;
            		break;
            	}
            }

        }

你可能感兴趣的:(字符串与switch)