1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <string> #include <iostream> #include <sstream> using namespace std; int main(void) { string s("X,1"); string t("1"); int i; istringstream ss(s); if (ss >> i) { cout << i << endl; } else { ss.clear(); string buf; while(ss.good() && getline(ss,buf,',')) cout << buf << endl; } return 0; }