if I'm understanding you correctly, you want to store just the digits? If so then maybe you are looking for something like this:
string s = "A year has 365 days";
vector<string> storedNums = {};
for(int i = 0; i < (s.length() - 1); i++) {
if (s[i] >= 48 && s[i] <= 57) {
storedNums.push_back(s[i]);
}
}
Here I'm using the ascii values between 48 and 57 (digit chars) to decipher if the current character is a digit. Using the while loop will put you in an infinite loop if the condition is true. This means once your iteration reached '3', it will continue to sit in the while loop. So your vector will keep calling push_back forever because the current condition is met and does not have a base case to break out of the while loop.
Edit:
This code has two mistakes that I did not initially catch. First, the vector should be a vector<char> and not a vector<string>. Second, it has come to my attention that the condition should not be i < s.length()-1 and it should be i < s.length(). The way I initially typed skips the last index in the loop and it works with the given string, however if "days" is taken out of the string, it will only print 36. The following code has been adjusted for readability and has been compiled to make sure it works:
// Example program
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
string s = "A year is 365";
vector<char> nums;
int length = s.length();
for(int i = 0; i < length; i++) {
if (s[i] >= '0' && s[i] <= '9') {
nums.push_back(s[i]);
cout << s[i];
}
}
}
v[i]. And what if the string doesn't start with a digit?if (s[i]>='0' && s[i]<='9) { while (s[i]>='0' && s[i]<='9) v[i].push_back(s[i]); i++; },ion the linewhile (s[i]>='0' && s[i]<='9) v[i].push_back(s[i]);?