Parsing strings

Hey guys, I was wondering if you can parse string according to user input, let's say the user inputs 33alpha or alpha33, is it possible to capture only the 33 in both the inputs? I tried using istringstream and takes the input as a string to parse it, however it only works for either one, not both. So guys, any idea I could make it work for both the inputs? Thanks in advanced.
Get input string. Examine each character in turn. When characters start being numbers, copy them to a new variable. When characters stop being numbers, stop copying them.
std::replace_if() would come in handy

1
2
3
4
5
6
std::vector<int> extract_integers( std::string str )
{
    std::replace_if( str.begin(), str.end(), [] ( char c ) { return !std::isdigit(c) ; }, ' ' ) ;
    std::istringstream stm(str) ;
    return std::vector<int>( std::istream_iterator<int>(stm), std::istream_iterator<int>() ) ;
}

Topic archived. No new replies allowed.