title: stream >> reading last line twice
body: <p>I am trying to parse <code>/proc/partitions</code> file. </p>
  
  <pre><code>major minor  #blocks  name
  
     8        0  976762584 sda
     8        1   99998720 sda1
     8        2          1 sda2
     8        3  103561216 sda3
     8        4  291514368 sda4
     8        5    1998848 sda5
  </code></pre>
  
  <p>This is the /proc/partitions file in my machine.</p>
  
  <pre><code>#include &lt;boost/cstdint.hpp&gt;
  #include &lt;fstream&gt;
  #include &lt;boost/algorithm/string/trim.hpp&gt;
  #include &lt;boost/format.hpp&gt;
  
  int main(){
    std::ifstream proc_partitions_stream("/proc/partitions");
    boost::int32_t disc_partition_line_count = -2; //-1 for headers, -1 for the empty line
    //so counter is 0 when it tries to read the real entries
    while(!proc_partitions_stream.fail()){
      if(disc_partition_line_count &gt;= 0){
        boost::uint16_t   major, minor;
        boost::uint64_t   blocks;
        std::string   label;
        proc_partitions_stream &gt;&gt; major &gt;&gt; minor &gt;&gt; blocks &gt;&gt; label;
        std::cout &lt;&lt; boost::format("%1% %2% %3% %4%") % major % minor % blocks % label &lt;&lt; std::endl;
        boost::algorithm::trim(label);      
      }else{
        std::string line;
        std::getline(proc_partitions_stream, line);
      }
      ++disc_partition_line_count;
    }
      return 0;
  }
  </code></pre>
  
  <p>But it reads <strong>the last line twice</strong>  Here is the program</p>
  
  <pre><code>8 0 976762584 [sda]
  8 1 99998720 [sda1]
  8 2 1 [sda2]
  8 3 103561216 [sda3]
  8 4 291514368 [sda4]
  8 5 1998848 [sda5]
  8 5 1998848 [] &lt;&lt; read the last line TWICE but didn't read the label
  </code></pre>