title: How to search for a word in a text file and if found print out the entire line
body: <p>My program needs to search for a word in a text file, and if it finds that word, to print out/display the entire line. Example:</p>
  
  <pre>
  employee   name    date joined    position       project        annual salary
  tom jones           1/13/2011     accountant    pricing         55000
  Susan lee           2/5/2007      Manager       policy          70000
  </pre>
  
  <p>User enters a search word:</p>
  
  <blockquote>
    <p>accountant</p>
  </blockquote>
  
  <p>Program searches text for <code>accountant</code>. When it finds it, it returns the following:</p>
  
  <pre>
  employee   name    date joined    position       project        annual salary
  tom jones           1/13/2011     accountant    pricing         55000
  </pre>
  
  <p>This is the code I came up with but it doesn't work.</p>
  
  <pre><code>void KeyWord(ifstream &amp;FileSearch)
  {
       string letters;
       int position =-1;
       string line;
       ifstream readSearch;
       cout&lt;&lt;"enter search word ";
       cin&gt;&gt;letters;
       "\n";
       FileSearch.open("employee");
       if(FileSearch.is_open())
       { 
           while(getline(FileSearch, line))
           {
               FileSearch&gt;&gt;line;
               cout&lt;&lt;line&lt;&lt;endl;
               position=line.find(letters,position+1);
               if(position==string::npos);
               if(FileSearch.eof())
                   break;
  
               cout&lt;&lt;line&lt;&lt;endl;
           }
  
       }
       cout&lt;&lt;"Cant find"&lt;&lt;letters&lt;&lt;endl;
   }
  </code></pre>