title: to find a word from a text file and then also display the line number in which the word lies using C++
body: <p>I am absolutely a beginner at programming. No this is not a homework either. I am trying to learn it by myself. As stated in the titel itself I would like to input a .txt file and find out a particular word from the file. But thats not exactly what I want. I rather want the line number in which the word lies, so that i can use this line number and print out all the lines in the .txt file after this particular line. I found this code on youtube where it showed me how to find the word. I modified it a bit and its now giving me the line in which the searched word states (NOT THE LINE NUMBER). I am attaching the code. </p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;stdio.h&gt;
  using namespace std;
  
  string find_word(string file, string word)
  {
    int offset;
    string line1;
    ifstream Myfile;
    Myfile.open(open);
  
    if (Myfile.is_open())
    {
      while (!Myfile.eof())
      {
        getline(Myfile, line1);
        if ((offset = line1.find(word,o)) != string::npos)
        {
          return line1;
        }
      }
      Myfile.close();
    }
    else
      cout &lt;&lt; "couldn't open...." &lt;&lt; endl;
  }
  
  int main ()
  {
    string c = find_word("test.txt", "$COOR");
    cout &lt;&lt; c;
    cin.get();
    return 0;
  }
  </code></pre>
  
  <p>right now the text file contains just 8 lines and "$COOR" lies in line 4. the program just gives me the entire line. But I want the line number so that I can print out the lines after line number 4.</p>
  
  <p>I would later like to test it for a file having many lines i.e. more than 50000000 or so.</p>