title: C++ searching text file for a particular string and returning the line number where that string is on
body: <p>Is there a particular function in c++ that can return the line number of a particular string i want to find?</p>
  
  <pre><code>ifstream fileInput;
  int offset;
  string line;
  char* search = "a"; // test variable to search in file
  // open file to search
  fileInput.open(cfilename.c_str());
  if(fileInput.is_open()) {
      while(!fileInput.eof()) {
          getline(fileInput, line);
          if ((offset = line.find(search, 0)) != string::npos) {
              cout &lt;&lt; "found: " &lt;&lt; search &lt;&lt; endl;
          }
      }
      fileInput.close();
  }
  else cout &lt;&lt; "Unable to open file.";
  </code></pre>
  
  <p>I want to add some codes at:</p>
  
  <pre><code>    cout &lt;&lt; "found: " &lt;&lt; search &lt;&lt; endl;
  </code></pre>
  
  <p>That will return the line number followed by the string that was searched.</p>