title: C++ string parsing ideas
body: <p>I have the output of another program that was more intended to be human readable than machine readable, but yet am going to parse it anyway. It's nothing too complex.</p>
  
  <p>Yet, I'm wondering what the best way to do this in C++ is. This is more of a 'general practice' type of question.</p>
  
  <p>I looked into Boost.Spirit, and even got it working a bit. That thing is crazy! If <em>I</em> was designing the language that I was reading, it might be the right tool for the job. But as it is, given its extreme compile-times, the several pages of errors from g++ when I do anything wrong, it's just not what I need. (I don't have much need for run-time performance either.)</p>
  
  <p>Thinking about using C++ operator &lt;&lt;, but that seems worthless. If my file has lines like "John has 5 widgets", and others "Mary works at 459 Ramsy street" how can I even make sure I have a line of the first type in my program, and not the second type? I have to read the whole line and then use things like <code>string::find</code> and <code>string::substr</code> I guess.</p>
  
  <p>And that leaves <code>sscanf</code>. It would handle the above cases beautifully </p>
  
  <pre><code>if( sscanf( str, "%s has %d widgets", chararr, &amp; intvar ) == 2 )
        // then I know I matched "foo has bar" type of string, 
        // and I now have the parameters too
  </code></pre>
  
  <p>So I'm just wondering if I'm missing something or if C++ really doesn't have much built-in alternative.</p>