Parsing lines stored in std::string's
I have to parse a text file with lines similar to that:
f 1/3/4 2/3/8 2/4/3
I store the line in a std::string. The question is: how can I store the numbers in integer variables? How can I mimic C''s scanf function?
Thanks!
Have you tried using std::istrstream?
It's not quite sscanf(), but it works well with std::string.
Edited by - I-Shaolin on May 2, 2001 8:15:17 PM
|
It's not quite sscanf(), but it works well with std::string.
Edited by - I-Shaolin on May 2, 2001 8:15:17 PM
You can also use the string.find () function to find the position of the next delimiter (your / ) in this case, and retrive a C style string (null terminated array of char) with string.c_str() to pass to atoi(). Then again you can just use the sting.c_str () function to get a C style string and use scanf() to parse it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement