How would I pull integers out of a string? I have the following string:
string my_string = "C(2)Fe(5)O(4)";
And I need to pull the numbers 2, 5, and 4 out of the string and store them in a different variable so I can multiply them by other numbers. Is there any way to do this?
#include <string>
int main()
{
std::string my_string = "C(2)Fe(5)O(4)";
for (unsignedint i=0; i<my_string.size(); ++i)
{
if(my_string[i] >= 48 && my_string[i] <=57) //character is a number in that case
my_string.erase(my_string.begin()+i);
}
}