Hello all,
So I am new to the whole STL List class, and I am a little confused. In the past I have always had two classes, a data class and a "linked list" class. So now I have a bit of a pickle when I try to make a list of objects using the STL. Essentially I have a class and I want to be able to read in many classes into the list. But I do not understand how to insert an object using the STL implementation. (list.insert() <---what do i put in the () )
I'm a noob to the STL list so its throwing me off!
Thanks in advance
/***************************
Devang N. Joshi
CSCI 271
Assignment Three
February 19th, 2011
STL Double Linked List
The purpose of this
assignment is to
gain experiance
using C++ built
in List STL
***************************/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <list>
using namespace std;
class cProg3
{
private:
char lname[21];
float avg;
int gSize;
public:
cProg3();
void Read_m(fstream &Infile);
void Read_g(fstream &Infile);
void Load();
};
/***Functions**/
cProg3::cProg3()
{
strcpy(lname,"");
avg = 0;
gSize = 0;
}
//------------------------------
void cProg3::Read_m(fstream &Infile)
{ Infile>>lname>>avg; }
//------------------------------
void cProg3::Read_g(fstream &Infile)
{ Infile>>lname>>gSize; }
//------------------------------
int main()
{
/***File Handlers***/
fstream Infile;
fstream Outfile;
/***Class Decleration***/
cProg3 Prog3,temp;
/***List Decleration***/
list<cProg3> theList;
list<cProg3>::iterator it;
/***Open Master Data and error check***/
Infile.open("/home/win.thackerw/271/peer/master.dat",ios::in);
if(!Infile)
{
cerr<<"FILE NOT FOUND!!!!!!!!!!!!!"<<endl;
exit(1);
}
else
{
cout<<"File Found & Opened"<<endl;
it = theList.begin();
it++;
while(!Infile.eof())
{
Prog3.Read_m(Infile);
theList.insert(it,temp);
it++;
}//while
}
return 0;
}//end main