c++ - Reading parts of a line (getline()) -
Originally a .txt file is searched for one word in this program and if it finds it, then it prints the line and line number. Even I have so far away.
Code:
#include "std_lib_facilities.h" int main () {string findword; Cout & lt; & Lt; "Enter the word to search. \ N"; Cin & gt; & Gt; Findword; Four filenames [20]; Cout & lt; & Lt; "Enter the file to search. \ N"; Cin & gt; & Gt; file name; Ifstream IST (filename); String line; String word; Int linecounter = 1; While (gateline (ITT, line)) {if (line.find (findword)! = String :: npos) {cout & lt; & Lt; Line & lt; & Lt; "" & Lt; & Lt; Line mark & lt; & Lt; Endl;} ++ line-counter; } Keep_window_open (); }
Resolve
You are searching:
if (line.find (keyword)! = String :: NPO) {...}