I'm a student having trouble with creating two vectors of objects for a homework assignment. The first vector creates fine, and prints out the values it imports (readM). The program hangs on the second vector(readT). I've checked the text files and they seem ok. I even tried substituting a simple vector object that only read one field per (and made sure the text file matched), and the program still hangs. It seems only to want to read one vector object. What in the @!@@@ am I doing wrong??? Any help much appreciated!
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
ifstream in;
struct Master {
int custnum;
string fcustname;
string lcustname;
float balanceDue;
};
struct Trans {
int trannum;
int custnum;
string ordertype;
string item;
int quantity;
float money; // Holds item cost or payment
};
void readM(vector<Master>& mastlist)
{
struct Master p;
in.open("master.txt");
while(!in.eof())
{
in>>p.custnum;
in>>p.fcustname;
in>>p.lcustname;
in>>p.balanceDue;
mastlist.push_back(p);
}
for(int i=0; i< mastlist.size(); i++) {
cout<<mastlist[i].custnum<<" ";
cout<<mastlist[i].fcustname<<" ";
cout<<mastlist[i].lcustname<<" ";
cout<<mastlist[i].balanceDue<<endl;
}
in.close();
}
void readT(vector<Trans>& translist)
{
struct Trans q;
in.open("trans.txt");
while(!in.eof())
{
in>>q.trannum;
in>>q.custnum;
in>>q.ordertype;
in>>q.item;
in>>q.quantity;
in>>q.money;
translist.push_back(q);
}
for(int i=0; i < translist.size(); i++) {
cout<<translist[i].trannum<<" ";
cout<<translist[i].custnum<<" ";
cout<<translist[i].ordertype<<" ";
cout<<translist[i].item<<" ";
cout<<translist[i].quantity<<" ";
cout<<translist[i].money<<endl;
}
in.close();
}
int main()
{
vector<Master> arrM;
vector<Trans> arrT;
readM(arrM);
readT(arrT);
cout<<endl<<endl<<endl;
cout<<"End of Master Record"<<endl;
system("pause");
return 0;
}