因爲switch後面判斷須要的只能是整數,字符串不行,那如何解決呢??code
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; } } }