/* virus4.cpp simulates the behavior of a virus detection program.
 *
 * Input:  the name of the input file; the string to be checked
 * Output: a message indicating whether the input string occurs
 *           in the input file
 **********************************************************************/

#include <iostream.h>                 // cin, cout, <<, >>
#include <fstream.h>                  // ifstream, open(), close(), eof()
#include <string>                     // string, getline(), find(), NPOS

void InteractiveOpen(ifstream & theIFStream);

int main()
{
   cout << "This program searches a file for a given string.\n";

   ifstream inStream;
   InteractiveOpen(inStream);
                                              // get the search string
   cout << "Enter the string being sought: ";
   string searchString;
   getline(cin, searchString);

   string lineOfText;

   for (;;)
   {
      getline(inStream, lineOfText);          // get a line from the file

      if (inStream.eof()) break;              // quit, if at eof
                                              //   display a "found" msg.
      if (lineOfText.find(searchString, 0) != NPOS)
         cout << "\n*** " << searchString 
              << " found in this file." << endl;
   }

   cout << "\nProcessing complete.\n";        // message to user
   inStream.close();                          // close the file

   return 0;

}

