Exercise 6: C++ Standard Template Library

STL list

Create a new program ex6.cc which will read a list of names from a simple text file into a list in memory, perform some simple manipulation then write the contents out to another file. Implement the steps below and after each stage compile and run your program.

  1. Use the standard template library to write a main program to read a list of names from a file name.txt. Use the STL string and list classes to build a linked list of strings. You will need the STL classes : <iostream> <fstream> <string> <list>
  2. Open the file and read its contents into the linked list. Try not to specify the size of the list but instead use the eof() member function of ifstream. Make sure you close the stream when you have finished with it.
  3. Next search the linked list and remove the entry "simon"
  4. Now reverse the order of the list
  5. Finally open a new file "name2.txt" and write the contents of the list to the file. The result should be in reverse order with the entry simon removed. Dont forget to close the stream.
  6. Add a few more names to the file "name.txt", does your program still work as it should ?