Reading parts of a line (getline())
<p>Basically this program searches a .txt file for a word and if it finds it, it prints the line and the line number. Here is what I have so far.</p>

<p>Code:</p>

<pre><code>#include "std_lib_facilities.h"

int main()
{
    string findword;
    cout &lt;&lt; "Enter word to search for.\n";
    cin &gt;&gt; findword;

    char filename[20];
    cout &lt;&lt; "Enter file to search in.\n";
    cin &gt;&gt; filename;
    ifstream ist(filename);

    string line;
    string word;
    int linecounter = 1;
    while(getline(ist, line))
    {
     if(line.find(findword) != string::npos){
             cout &lt;&lt; line &lt;&lt; " " &lt;&lt; linecounter &lt;&lt; endl;}
     ++linecounter;
     }

     keep_window_open();
}
</code></pre>

<p>Solved.  </p>
