Regular expressions can often be used for parsing strings. Use capture groups (parentheses) to get the various parts of the line being parsed.
For instance, to parse an expression like foo: [3 4 56], use the regular expression (.*): \[(\d+) (\d+) (\d+)\]. The first capture group will contain "foo", the second, third and fourth will contain the numbers 3, 4 and 56.
If there are several possible string formats that need to be parsed, like in the example given by the OP, either apply separate regular expressions one by one and see which one matches, or write a regular expression that matches all the possible variations, typically using the | (set union) operator.
Regular expressions are very flexible, so the expression can be extended to allow more variations, for instance, an arbitrary number of spaces and other whitespace after the : in the example. Or to only allow the numbers to contain a certain number of digits.
As an added bonus, regular expressions provide an implicit validation since they require a perfect match. For instance, if the number 56 in the example above was replaced with 56x, the match would fail. This can also simplify code as, in the example above, the groups containing the numbers can be safely cast to integers without any additional checking being required after a successful match.
Regular expressions usually run at good performance and there are many good libraries to chose from. For instance, Boost.Regex.
std::getline(), put them into a string stream, and parse the individual lines from that, using whatever delimiter you want for subsequent calls tostd::getline()on the string stream. Would this answer help you to get started?scanfon that very same question. It's not that I don't know how to do this in C++, the problem is that whenever I try I end up with something along the lines you're proposing.bool read_delimiter(std::istream&, char delim),template<typename T> T& read_value(std::istream&,T&),template<typename T> T& read_delimited_value(std::istream&,T&,char ldelim, char rdelim)aren't hard to come up with and can take you a long way towards a simple parser. Of course, when speed is a must, all this is to slow. But for reading simple config files, it's usually enough.