/* G Hagopian--PPP11 exercise 02
Write a program that given a file name and a word 
outputs each line that contains that word together with 
the line number. Hint: getline().
*/
#include "std_lib_facilities.h"

void doThat(ifstream&,string);

int main() {
	string targetWord, fname;
	cout << "Enter a filename for reading: ";
	cin >> fname;
	ifstream ifs(fname);
	cout << "What's your target word? ";
	cin >> targetWord;
	doThat(ifs,targetWord);
}

void doThat(ifstream& ifs, string target) {
	string input, checkWord;
	int lineNo{ 0 };
	while (getline(ifs, input)) {
		istringstream iss(input);
		string word;
		while (iss >> word) {
			if (word == target) {
				cout << lineNo << ". " << input << endl;
				break;
			}
		}
		++lineNo;
	}
}