Simple string parsing with C++
<p>I've been using C++ for quite a long time now but nevertheless I tend to fall back on <code>scanf</code> when I have to parse simple text files. For example given a config like this (also assuming that the order of the fields could vary):</p>

<pre><code>foo: [3 4 5]
baz: 3.0
</code></pre>

<p>I would write something like:</p>

<pre><code>char line[SOME_SIZE];
while (fgets(line, SOME_SIZE, file)) {
    int x, y, z;
    if (3 == sscanf(line, "foo: [%d %d %d]", &amp;x, &amp;y, &amp;z)) {
        continue;
    }
    float w;
    if (1 == sscanf(line, "baz: %f", &amp;w)) {
        continue;
    }
}
</code></pre>

<p>What's the most concise way to achieve this in C++? Whenever I try I end up with a lot of scaffolding code.</p>
