title: C++ How to load a textfile and adding the content to a class?
body: <p>I am trying to learn how to use classes and I figured I'd create some sort of supermarket system to aid me with learning. After I have saved all the values from my text file into the temp variables, how do I then use them to create an object? I assume I want one object per item you can "buy"?</p>
  
  <p>If you have any other tips on how to improve my code, please mention them as I just started with C++ a few days ago.</p>
  
  <p>My text file looks like:</p>
  
  <pre><code>42 68 Apples
  35 1 Oranges
  70 25 Bananas
  </code></pre>
  
  <p>And my code is below:</p>
  
  <pre><code>// Classes.cpp : Defines the entry point for the console application.
  //
  
  #include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;vector&gt;
  
  class Products {
  private:
      int price;
      int ID;
      int quantity;
  
  public:
      void setPrice(int newPrice) {
          price = newPrice;
      }
      void setID(int newID) {
          ID = newID;
      }
      void setQuantity(int newQuantity) {
          quantity = newQuantity;
      }
  
      int getPrice() {
          return price;
      }
      int getID() {
          return ID;
      }
      int getQuantity() {
          return quantity;
      }
  
  };
  
  
  int main()
  {
      std::string line;
      std::string input;
      std::string temp;
      std::string temp2;
      std::string temp3;
  
      int counter = 0;
      while (input != "e" &amp;&amp; input != "r") {
          std::cout &lt;&lt; "Do you want to (r)ead the inventory or (e)dit it? (input 'r' or 'e'): ";
          getline(std::cin, input);
      }
      if (input == "r") {
          std::ifstream pFile ("products.txt");
          if (pFile.is_open()) {
              while (getline(pFile, line)) {
                  std::istringstream iss(line);
                  iss &gt;&gt; temp &gt;&gt; temp2 &gt;&gt; temp3;
                  counter++;
  
  
              }
          }
  
      }
      return 0;
  }
  </code></pre>