SWITCH文
int i; switch(i){ case 1: break; case 2: break; case 3: break; default: break; }
サンプル
#include <iostream> #include <string> using namespace std; //---------- コマンドラインから1行拾う ---------- string strGetline(){ string strBuff; char cBuff; while(1){ cin.get(cBuff); if(cBuff == '\n'){ break; } strBuff += cBuff; } return strBuff; } //---------- コマンドライン引数が無い場合の入力画面 ---------- void vInputScreen(int nArgc, char **szArgv) { string strBuff; SELECT_FARMAT:; cout << "\n"; cout << "\tThe compressed format is selected.\n"; cout << "\n"; cout << "\t\t1: EXIT\n"; cout << "\t\t2: LZH\n"; cout << "\t\t3: ZIP\n"; cout << "\n"; cout << "\t\tSelect a value between 1 and 3 >> "; switch(atoi(strGetline().c_str())){ case 1: throw 1; break; case 2: sprintf(szArgv[1], "-CompressLzh"); break; case 3: sprintf(szArgv[1], "-CompressZip"); break; default: cout << "\n\t\tPlease enter a value within the range !!!\n" << endl; goto SELECT_FARMAT; break; } }