title: C++ How do we find each line of a word from a text file?
body: <p>I am reading a text file word for word and I am trying to find the number of the line the word is in.  For example if I had the following:</p>
  
  <pre><code>Dog Cat
  Car 
  Truck
  </code></pre>
  
  <p>Dog is found on line one, Cat is found on line one, Car line two, and Truck line 3.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>int main(){
  string word;
  ifstream inFile;
  Node* rootPtr = NULL; // Pointer to the root node
  
  inFile.open("example.txt");
  if (!inFile)
      cout &lt;&lt; "Unable to open text file";
  
  while (inFile &gt;&gt; word) {
      if (word == "#")
          break;
  
      /* THIS DOES NOT WORK! Most likely because my text file doesn't contain /n but this is the
      kind of logic I am looking for
      else if (word == "/n"){
          counter++;
          cout &lt;&lt; counter;
      }
      */
  
      else{
      rootPtr = Insert(rootPtr,word.substr(0,10));
      }
  }
  inOrderPrint(rootPtr);
  inFile.close();
  }
  </code></pre>
  
  <p>You can ignore anything to do with the pointers.  That is for some other stuff.  I have tried figuring out how to check for the end of the line and creating a counter that will increment every time then end of a line is found but I was unsuccessful.</p>
  
  <p>Thanks for your help! </p>