これは c++11 で実行できます。このソリューションは堅牢で、スペースを無視します。
これは、ubuntu 13.10 の clang++-libc++ でコンパイルされます。gcc にはまだ完全な正規表現が実装されていませんが、代わりにBoost.Regexを使用できることに注意してください。
編集: 負の数の処理を追加しました。
#include <regex>
#include <iostream>
#include <string>
#include <utility>
using namespace std;
int main() {
regex pattern(R"(\s*(-?\d+)\s+(-?\d+)\s*|\s*([[:alpha:]])\s*)");
string input;
smatch match;
char a_char;
pair<int, int> two_ints;
while (getline(cin, input)) {
if (regex_match(input, match, pattern)) {
if (match[3].matched) {
cout << match[3] << endl;
a_char = match[3].str()[0];
}
else {
cout << match[1] << " " << match[2] << endl;
two_ints = {stoi(match[1]), stoi(match[2])};
}
}
}
}