title: How do I compare two different strings from two separate text files?
body: <p>I am a c++ rookie and do not know what I am doing wrong. My assignment is to compare two different .txt files, each containing an item along with either the number of items and the price of that item. I am then trying to print the names and prices of the items. Lets say I am using the .txt file namesAndQuantity.txt which includes:</p>
  
  <pre><code>3 books
  4 pens
  </code></pre>
  
  <p>And a .txt file namesAndPrice.txt which includes:</p>
  
  <pre><code>pens 3.45
  books 19.55
  </code></pre>
  
  <p>The code I am using only prints out the first match:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;cmath&gt;
  
  int main(){
      string nameOfItemP, nameOfItemQ;
      double priceOfItem;
      int numberOfItems;
      ifstream inData;
      ifstream inData2;
      inData.open("namesAndQuantity.txt");
      inData2.open("namesAndPrice.txt");
      while (inData&gt;&gt;numberOfItems&gt;&gt;nameOfItemQ){
          while (inData2&gt;&gt;nameOfItemP&gt;&gt;priceOfItem){
              if (nameOfItemP==nameOfItemQ){
                 cout&lt;&lt;nameOfItemQ&lt;&lt;endl;
                 cout&lt;&lt;priceOfItem;
          }   
      }
  }
  </code></pre>
  
  <p>This code only prints out the first line: </p>
  
  <pre><code>books
  19.55
  </code></pre>
  
  <p>What can I do to better it?</p>