Here is one way to do it -- first read the entire line into a std::string object then parse it
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> sList;
vector<float> fList;
string name;
float f;
string line = "X = {1.0, 2.0, 3.0}";
// extract the name which
size_t pos = line.find(' ');
name = line.substr(0,pos);
line = line.substr(pos+1);
pos = line.find('{');
line = line.substr(pos+1);
while( (pos = line.find(',')) != string::npos)
{
string n = line.substr(0,pos);
f = (float)atof(n.c_str());
fList.push_back(f);
line = line.substr(pos+1);
}
// now do the last float in the line
f = (float)atof(line.c_str());
fList.push_back(f);
return 0;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343