int integers;
std::list<int> integersList = {};
string token;
while(iss >> token)
{
if(stringstream(token) >> integers)
{
integersList.push_back(integers);
}
}
One of the tokens I need to parse is
U<sub>54778</sub><br
The istringstream doesn’t tokenise the integer inside of it, it only splits in along the spaces.
All the other integer tokens in the string are separated by spaces but this one is not.
This will most probably work with a stringstream in an easy way.
As written in the comments, it is better to use a "regex" for this. Very fortunately C++ has a build-in "regex" library. You may read here about it.
And even better, there is an iterator, with which you can iterate over all patterns in a
std::string: the std::sregex_token_iterator.This gives you very powerful possibilities, because you can match many different patterns by a regex. Please read about it here.
With that, you can come up with a very simple program like the below:
Please note: If you need to validate the correct format or range for an integer, then the regex will get more complicated.