Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <list>
  6. #include "item.h"
  7.  
  8. using namespace std;
  9.  
  10. void initializeList(list<item*> &alist);
  11.  
  12. int main()
  13. {
  14.     list<item*> itemList;
  15.     list<item*>::iterator i;
  16.  
  17.     initializeList(itemList);
  18.  
  19.     for (list<item*>::iterator i = itemList.begin(); i != itemList.end(); ++i)
  20.         cout << **i << endl;
  21.  
  22.     while (!itemList.empty())
  23.     {
  24.         delete itemList.front();
  25.         itemList.pop_front();
  26.     }
  27.     return 0;
  28. }
  29.  
  30. void initializeList(list<item*> &alist)
  31. {
  32.     string fileName;
  33.     ifstream ins;
  34.     char choice;
  35.     item *stuff;
  36.  
  37.     cout<<"Do you wish to fill the list from a file? (Y/N)";
  38.     cin>>choice;
  39.  
  40.     if (choice =='y' || choice == 'Y')
  41.     {
  42.         cout << "File name: " ;
  43.         cin >> fileName;
  44.         ins.open(fileName.c_str());
  45.        
  46.         if (!ins.fail())
  47.         {
  48.             while (!ins.eof())
  49.             {
  50.                 stuff = new item;
  51.                 ins >> *stuff;
  52.                 alist.push_back(stuff);
  53.             }
  54.         }
  55.         else
  56.             cout << "file failed to open" << endl;
  57.     }
  58. }
Add Comment
Please, Sign In to add comment