#include <string>
#include <vector>
using namespace std;
int main()
{
//This is your source string
string Source = "foo $RESULT :(0.2374742, 0.267722) $STATES :{1, 3, 5} fo0";
//Get the $RESULT section of the string, encapsulated by ( )
string Results = Source .substr(Source .find("(") + 1, (Source .find(")") - Source .find("(")) - 1);
//Get the $STATES section of the string, encapsulated by { }
string States = Source .substr(Source .find("{") + 1, (Source .find("}") - Source .find("{")) - 1);
vector<double> ResultsList;
vector<int> StatesList;
//While the Results string still has remaining ", " token/seperators in it
while(Results.find(", ") != string::npos)
{
//Get the next value and insert it into the vector (converting it from string to float using atof)
ResultsList.push_back(atof(Results.substr(0, Results.find(", ")).c_str()));
//Crop that off the oringal string
Results = Results.substr(Results.find(", ") + 2);
}
//Push the final value (no remaning tokens) onto the store
ResultsList.push_back(atof(Results.c_str()));
//Exactly the same operation with states, just using atoi to convert instead
while(States .find(", ") != string::npos)
{
StatesList.push_back(atoi(States.substr(0, States .find(", ")).c_str()));
States = States.substr(States.find(", ") + 2);
}
StatesList.push_back(atoi(States.c_str()));
return 0;
}