I'm doing an assignment for school which is to simulate the grep command in C++. We are to take in a word to search, an input file to search through, and output file to output the results. The only text that should be in the output file is the contents of each line that had the search word in it, with a line number of where it was in the input file. We are supposed to use the functions of <fstream>.
I'm having issues outputting just the line the word appeared on. I can't seem to get my head around it.
What is that while loops supposed to do. line never changes in it, so the third condition is useless. Of course it will copy the rest of the file. What you need to do is simply out << linenumber << ' ' << line << '\n';