file reading using getline()

i encounterd a question like

*Create a program that opens a file (the first argument on the command line) and searches it for any one of a set of words (the remaining arguments on the command line). Read the input a line at a time, and print out the lines (with line numbers) that match.*

when i try to solve this question,i read the whole line at a time using getline() member function,but this make a problem by comparing the whole line read with a single word entered in the command line.
here is part of the code i wrote to solve the problem

/*********************************/
int counter=1; //for the first line
bool found=false;
ifstream in;
in.open(argv[1]);
string str;
for(int i=2;i<argc;i++)
{
while(!in.eof())
{
std::getline(in,str);
if(str==argv[i])
{
cout<<"The word "<<"' "<<argv[i]<<" '"<<" has been found in line "<<counter<<endl;
found=true;
}
counter++;
}
if(found==false)
cout<<"The word "<<argv[i]<<" is not found"<<endl;
/**********************************/ }
please help me solving this problem.Thanks in advance!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main(int argc, char* argv[])
{
	std::fstream in(argv[1], std::ios::in);
	for(int i = 2; i < argc; ++i)
	{
		std::string line;
		std::size_t lineNum = 0u;
		while(std::getline(in, line))
		{
			++lineNum;
			if(std::string::npos != line.find(argv[i]))
			{
				std::cout << "Word: " << argv[i] << ", was found on line: " << lineNum << std::endl;
			}
		}
		in.clear();
		in.seekg(0, std::ios::beg);
	}
	in.close();

	return 0;
}
Topic archived. No new replies allowed.