Saturday, November 21, 2009

sscanf

to read in the numbers in the following string

string s = "1000 ml of water, weighing 1000 g"


int v;
sscanf(s, "%d ml of", &v);

size_t p = s.find(',');

int m;
sscanf(s.substr(p+2, s.length()-p).c_str(), "weighing %d", &m);



Note: the use of c_str() and sscanf()