I'm reading input using istringstreams for easy conversion from string to integer. I'm having trouble reading the line when it contains errors, such as "1 45 3 XXXX 45 X", where i want it to simply ignore the letters. Normally, without any errors i would just have done:
string s = "1 2 34 5 6";
istringstream stream(s);
int temp;
cout << s << " -> ";
while(stream >> temp){
//do something with temp for ex:
cout << temp << " ";
}
This would give
"1 2 34 5 6" -> 1 2 34 5 6
Obviously this doesnt work when i have a string of the form "1 45 3 XXXX 45 X" as it would break at XXXX and not continue. But what i would like to get is:
"1 45 3 XXXX 45 X" -> 1 45 3 45
So, i know the problem, but im stuck on how to solve it. I got this feeling there should be a very simple solution to this, but i cant figure it out, and most examples ive searched for online don't take errors in data into account or are too advanced for my needs.