*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!