Начальная версия, с использованием <algorithm>
:
string input("aasdf43");
string matches("01234567890");
string::iterator iter = find_first_of(input.begin(), input.end(),
matches.begin(), matches.end());
string next(iter, input.end());
stringstream intStream(next);
int intValue;
intStream >> intValue;
РЕДАКТИРОВАТЬ: Лучше использовать функцию-член:
string input("aasdf43");
string matches("0123456789");
size_t offset = input.find_first_of(matches);
string next(input.substr(offset));
stringstream intStream(next);
int intValue;
intStream >> intValue;
Только для примера - версия <algorithm>
, не требующая проверкипротив всех цифр.
string::reverse_iterator iter = find_if_not(input.rbegin(), input.rend(),
([&](char c) { return c >= '0' && c <= '9';}));
reverse(input.rbegin(), iter);
string reversed(input.rbegin(), iter);
stringstream intStream(reversed);
int intValue;
intStream >> intValue;