I've got a vector of strings wherein if the 1st character is "1" then I need to push the integer (represented as a string) into a vector else I just need to print the 1st char. While using stringstream the following is the code ive written.
vector<string> arr = {"1 23", "2", "1 45", "3", "4"};
vector<int> v;
for(string x : arr){
stringstream ss(x);
string word;
string arr[2];
int i =0 ;
while(ss >> word){
arr[i++] = word;
}
i = 0;
if(arr[0] == "1")
v.push_back(atoi(arr[1]));
else
cout << arr[0] << endl;
Instead of using an array arr, is there a way to take the next word from stringstream once the first word is "1"? Because when I tried the stringstream began all over again from start.