ただの覚え書き
C++の入力
1000行以上の入力とか
#include <iostream> #include <string> using namespace std; int main(void){ string str; while(cin >> str){ cout << str << endl; } return 0; }
スペース区切りの文字列を改行で出したい
#include <iostream> #include <sstream> // stringstream用 #include <string> using namespace std; int main(void){ string str = " スペース区切りで出力したい文字列"; istringstream iss(str); // stringstreamに変換(よくわかってない) string outstr; // 出力用の変数 while(iss > outstr){ // 文字列をスペース区切りで格納 cout << outstr << endl; } return 0; }
まとめ
普段C++で文字列入力あんま使ってこなかったから学習用に
サイトで勉強した際に結構困ったので覚え書きを作ってみた。
ゲーム作ってるときに1000行以上の入力とかしない・・・