string s = "1_3_2_4_"; stringstream ss(s); string temp; while (getline(ss, temp, '_')) { cout << temp << endl; }