I hate to do your homework for you but, I just did something like this, and I would like to share. Your making this harder than it needs to be. If you want a good example of this project type find /? at a command prompt.
If you want to read about this yourself, I think the links below would help.
http://www.cplusplus.com/reference/string/string/find/
http://www.cplusplus.com/doc/tutorial/files/
http://www.cplusplus.com/articles/DEN36Up4/
/* Search file for String */
/* Command String Filename */
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
int offset;
string line;
ifstream InputFile;
// Check the value of argc. If not enough parameters have been passed, inform user and exit.
if (argc != 3) // Inform the user of how to use the program
{
// Add user directions here if desired
} // End if
else { // if we have enough parameters...
InputFile.open (argv[2]); // File List
if(InputFile.is_open())
{
cout << "Searching " << argv[2] << endl;
while(!InputFile.eof())
{
getline(InputFile,line);
if ((offset = line.find(argv[1], 0)) != string::npos)
{
cout << argv[1] << " found " << argv[2] << endl;
break; // If match found, this break will stop the program for searching further.
} // End if
} // End while
} // End if
InputFile.close();
}
return 0;
}