入力ストリームで数値を切り出す
char型変数で1文字取って捨ててます。
#include <iostream> int main(){ int y, m, d; char c; std::cin >> y >> c >> m >> c >> d; std::cout << y << "年" << m << "月" << d << "日" << std::endl; return 0; }
Input:
2012/05/18
Output:
2012年5月18日
標準入力でない文字列であればstringstream使うのも。
#include <iostream> #include <sstream> int main(){ std::stringstream ss("0v0"); //顔文字 int eye; char mouth; ss >> eye >> mouth >> eye; //分解 return 0; }
日付をそれぞれint型に流し込むのは感動しました。おもしろいですね!