How to parse a string into a vector<int>

I was wondering how to convert a string, say "1234" into a vector, say vec, where vec[0] = 1, vec[1] = 2,... and so on.

You could easily iterate through the string and 'convert' the single characters to integers.

1
2
3
4
5
6
7
  std::string input = "1234";
  std::vector<int> vec;
  
  for (size_t i = 0; i < input.size(); ++i)
  {                                 // This converts the char into an int and pushes it into vec
    vec.push_back(input[i] - '0');  // The digits will be in the same order as before
  }
Thanks!!
Topic archived. No new replies allowed.