// Mr. Minich
// CMPSC 101
// Ch. 5 Demo Program #5
// January 30, 2000
// Purpose - to demonstrate reading data from a file, closing the file, and then writing to the same file.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
   string nextBookmark; // Netscape bookmark

   ifstream infile("bookmarks.txt"); // bookmark file
   ofstream outfile; // file to overwrite bookmarks

   while (!infile.eof())
   {
      infile >> nextBookmark;
      cout << nextBookmark << endl;
   }

   infile.close();
   outfile.open("bookmarks.txt");

   cout << "Type your new bookmarks. This will overwrite your old bookmarks!" << endl;
   cout << "Type xxx to quit: ";

   while (nextBookmark != "xxx")
   {
      cin >> nextBookmark;

      if (nextBookmark != "xxx")
      {
         outfile << nextBookmark << endl;
      }

   }

   outfile.close();

   return 0;
}// end of main