蛙の井戸見聞記 Pretty frog in a well who knows nothing of the great web ocean!

~~ 好奇心は猫をも殺す Curiosity Kills the Cat ~~ ♪欲しいモノ・食べたいモノ・ネットで集めた情報と日々の記録の倉庫♪ Logging my life... Since 2003.12  

c++で標準入力からのスペース区切り文字列を分割する

string sline, sp, main_command, parameters;
while(getline(cin,sline)){//行をまるごと読み込む
 sp=sline.find(" ");//空白を探す
 main_command=sline.substr(0,sp);//最初のワードを読み込む
 cout << main_command << endl;//ちょっと表示してみる
 parameters=sline.substr(sp+1,sline.length());//残りの部分を格納
 cout << parameters << endl;//確認のため表示
 if(main_command.find("quit")<main_command.length()){//quitと打ち込まれたら抜ける。
  break;
 }else if(main_command.find("help")<main_command.length()){//helpでメッセージを表示する
  cout << "this is help message << endl;
 }
}//while
return 0;

参考ページ:
http://next1.cc.it-hiroshima.ac.jp/CPPPUBLISH/node10.html