title: Wrong reading of text file in c++
body: <p>I just want to read a text file and store the data into a vector. Thereby the value weight should be sum till the limit is reached. The first four lines will be read correctly but the following will not read. What is the mistake?   </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;limits&gt;
  
  /*
  Data.txt 
  
  John
  6543
  23
  
  Max
  342
  2
  
  A Team
  5645
  23
  */
  
  struct entry
  {
      // passengers data
      std::string name;
      int weight; // kg
      std::string group_code; 
  };
  
  void reservations()
  {
      std::ofstream file;
      file.clear();
      file.open("reservations.txt");
      file.close();
  }
  
  entry read_passenger(std::ifstream &amp;stream_in)
  {
      entry passenger;
      if (stream_in)
      {
          std::getline(stream_in, passenger.name); 
          stream_in &gt;&gt; passenger.weight;
          std::getline(stream_in, passenger.group_code);
          stream_in.ignore(std::numeric_limits&lt;std::streamsize&gt;::max(), '\n');
          return passenger;
      }
  
      return passenger; 
  }
  
  int main(void)
  {
      std::ifstream stream_in("data.txt"); 
      std::vector&lt;entry&gt; v; // contains the passengers data
      const int limit_total_weight = 10000;   // kg
      int total_weight = 0;                   // kg
      entry current;
      while (!stream_in.eof())
      {
          current = read_passenger(stream_in);
          total_weight = total_weight + current.weight;
          std::cout &lt;&lt; current.name &lt;&lt; std::endl;
          if (total_weight &gt;= limit_total_weight)
          {
              break;
          }
  
      }
          return 0;
  }
  </code></pre>