The easiest way is by extracting substrings rather than individual characters. Use operator +
to concetanate them, and call stoi
on the resulting string:
vec.push_back(stoi(string.substr(0, 1) + string.substr(1, 1)));
// vec now ends with 12
The above will concatenate strings at arbitrary locations in the source string. If you really need only extract consecutive characters, a single call to substr
will suffice:
vec.push_back(stoi(string.substr(0, 2)));