title: Reading data from a file and storing it into a vector
body: <p>I'm trying to read a list of items from from a file and then store them into a vector. The issue is my code is adding the last item to the vector twice and I'm not sure why the it keeps reading the file even though the program has reached the end. </p>
  
  <p>Here's what's in the text file. The "Oranges" line appears twice when I display the contents of the vector. </p>
  
  <p>Apples-pounds-10 2</p>
  
  <p>Oranges-pounds-5 6</p>
  
  <p>Here's the code
  //Read the contents of the list to a file</p>
  
  <pre><code>while (!inputFile.fail())
  {   
  
      //Extract the line from the list
      getline(inputFile,item_name,'-');
      getline(inputFile,item_unit,'-');
      inputFile &gt;&gt; item_amount;
      inputFile &gt;&gt; item_price;
  
      //Create an instance of the item object
      Item New_Item(item_name, item_unit, item_amount,item_price);
  
      //Push it to the list vector
      list.push_back(New_Item);
  }
  
  //Close the file
  inputFile.close();
  </code></pre>