title: C++: Reading in from a file and displaying individual items
body: <p>So I have a .txt file I'm supposed to be reading information in from and displaying in a neat little table. Here's a snippet of the .txt files contents
  in the format </p>
  
  <p>Farm name, item count, item, price, total price</p>
  
  <pre class="lang-none prettyprint-override"><code>Collins Farm, 43900 tomatoes 0.67 29413
  Bart Smith Farms, 34910 cassavas 0.99 34560.9
  Allen Farms, 117 coconuts 0.54 63.18
  </code></pre>
  
  <p>etc...</p>
  
  <p>It should print out in the console as</p>
  
  <blockquote>
    <p>Collins Farm (some spaces here) 43900 items contributed totaling $29413.00</p>
  </blockquote>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  int addLine(int);
  
  int main()
  {
  using std::ifstream;
  
  ifstream myFile;
  myFile.open("ASSGN6-B.txt");
  
  string farmName;
  int itemCount;
  string itemName;
  double itemPrice;
  double totalPrice;
  
  if (!myFile)
  {
      cout &lt;&lt; "File open failed!" &lt;&lt; endl;
  }
  else
  {
      cout &lt;&lt; "\t\t\t=========================================================" &lt;&lt; endl;
      cout &lt;&lt; "\t\t\t=               FARMER'S MARKET INVENTORY               =" &lt;&lt; endl;
      cout &lt;&lt; "\t\t\t=========================================================" &lt;&lt; endl;
  
      while (myFile.good())
      {
          getline (myFile, farmName);
          getline (myFile, itemName);
          myFile &gt;&gt; itemName &gt;&gt; itemPrice &gt;&gt; totalPrice;
          cout &lt;&lt; farmName &lt;&lt; "       " &lt;&lt; itemCount &lt;&lt; " items contributed totaling $" &lt;&lt; totalPrice &lt;&lt; endl;
  
      }
  }
  
  
  myFile.close();
  return 0;
  }
  </code></pre>
  
  <p>This is what I've been messing with trying to figure out how this input stuff works. I guess what I really don't get is how it's supposed to know which item is which. I previously thought it just read in a line at a time only but theres's gotta be a way to separate the items even on the same line and print them all separately in the console.</p>
  
  <p>Also, some farm names appear twice in the .txt file and I'm supposed to combine their data into one line if it's a duplicate. Help with this would be appreciated too.</p>
  
  <p>Thanks.</p>