Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- #include <list>
- #include "item.h"
- using namespace std;
- void initializeList(list<item*> &alist);
- int main()
- {
- list<item*> itemList;
- list<item*>::iterator i;
- initializeList(itemList);
- for (list<item*>::iterator i = itemList.begin(); i != itemList.end(); ++i)
- cout << **i << endl;
- while (!itemList.empty())
- {
- delete itemList.front();
- itemList.pop_front();
- }
- return 0;
- }
- void initializeList(list<item*> &alist)
- {
- string fileName;
- ifstream ins;
- char choice;
- item *stuff;
- cout<<"Do you wish to fill the list from a file? (Y/N)";
- cin>>choice;
- if (choice =='y' || choice == 'Y')
- {
- cout << "File name: " ;
- cin >> fileName;
- ins.open(fileName.c_str());
- if (!ins.fail())
- {
- while (!ins.eof())
- {
- stuff = new item;
- ins >> *stuff;
- alist.push_back(stuff);
- }
- }
- else
- cout << "file failed to open" << endl;
- }
- }
Add Comment
Please, Sign In to add comment