title: Skipping input stream values
body: <p>Is there any easy mechanism to skip until the next whitespace with a C++ input stream (like <code>ifstream</code>)?</p>
  
  <p>I know that I can use <code>ignore</code> if I know how many characters to skip or what delimiter to expect. But IMO it's ugly to use <code>ignore</code> when <code>operator&gt;&gt;</code> usually just reads to the next whitespace without supplying any additional parameters. I could also use a dummy, but that only makes matters worse. </p>
  
  <h3>Example</h3>
  
  <pre><code>auto importantInfo1 = 0;
  auto importantInfo2 = 0;
  auto someDummy = 0; // This is ugly and doesn't clearly express the intent
  
  file &gt;&gt; importantInfo1 &gt;&gt; someDummy &gt;&gt; importantInfo2;
  </code></pre>
  
  <p>Also in some cases I will need more than one dummy if I need to handle different datatypes in the "skip"-case. </p>
  
  <p>I would imagine something like this:</p>
  
  <pre><code>file &gt;&gt; importantInfo1;
  file.skip&lt;int&gt;(1);
  file &gt;&gt; importantInfo2;
  </code></pre>
  
  <p>Or maybe even better:</p>
  
  <pre><code>auto importantInfo1 = 0;
  auto importantInfo2 = 0;
  
  file &gt;&gt; importantInfo1 &gt;&gt; skip&lt;int&gt; &gt;&gt; importantInfo2;
  </code></pre>
  
  <p>I imagine such a solution would also perform better than actually parsing and storing the value somewhere when it is never needed. </p>
  
  <h2>Possible solution</h2>
  
  <p>Made this solution using the answers provided. It's basically the same as the accepted answer, but it doesn't need a temporary. Instead, it skips the first whitespaces, then skips any character except whitespaces until whitespace is reached again. This solution may use 2 while loops but doesn't need to know about the extracted type. I'm not saying this is a high performance solution or anything fancy, but it makes the resulting code shorter, cleaner and more expressive. </p>
  
  <pre><code>template&lt;typename CharT, typename Traits&gt;
  inline std::basic_istream&lt;CharT, Traits&gt;&amp; skip(std::basic_istream&lt;CharT, Traits&gt;&amp; stream)
  {
      while (stream &amp;&amp; std::isspace(stream.peek())) stream.ignore();
      while (stream &amp;&amp; !std::isspace(stream.peek())) stream.ignore();
      return stream;
  }
  </code></pre>