title: C++ alternative for parsing input with sscanf
body: <p>Assuming my program expects arguments of the form <code>[ 0.562 , 1.4e-2 ]</code> (i.e. pairs of floats), how should I parse this input in C++ without regular expressions? I know there are many corner cases to consider when it comes to user input, but let's assume the given input closely matches the above format (apart from further whitespace).</p>
  
  <p>In C, I could do something like <code>sscanf(string, "[%g , %g]", &amp;f1, &amp;f2);</code> to extract the two floating point values, which is very compact.</p>
  
  <p>In C++, this is what I've come up with so far:</p>
  
  <pre><code>std::string s = "[ 0.562 , 1.4e-2 ]"; // example input
  
  float f1 = 0.0f, f2 = 0.0f;
  
  size_t leftBound = s.find('[', 0) + 1;
  size_t count = s.find(']', leftBound) - leftBound;
  
  std::istringstream ss(s.substr(leftBound, count));
  string garbage;
  
  ss &gt;&gt; f1 &gt;&gt; garbage &gt;&gt; f2;
  
  if(!ss)
    std::cout &lt;&lt; "Error while parsing" &lt;&lt; std::endl;
  </code></pre>
  
  <p>How could I improve this code? In particular, I'm concerned with the <code>garbage</code> string, but I don't know how else to skip the <code>,</code> between the two values.</p>