I am writting a program that makes use of a vector of objects. Every time I add an object the windows system encounters a problem and needs to be closed.
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
class Catalogue
{
public:
string vendor;
string item;
float price;
int code;
ifstream in;
Catalogue()
{
in.open("catalogue.txt",ios::in);
}
public:
void read()
{
in>>vendor>>item>>price>>code;
}
};
void main()
{
Catalogue cat;
Catalogue &cats = cat;
vector<Catalogue> catalogue;
string s;
while(!cat.in.eof())
{
cat.read();
catalogue.push_back(cat);
cout<<catalogue.size();
}
for(int counter = 0; counter != catalogue.size(); counter++)
{
//cout<< catalogue[counter].vendor<<" - " << catalogue[counter].item <<" - " << catalogue[counter].price<<" - "<< catalogue[counter].code <<'\n';
}
}
I cannot see why it is crashing, can a fresh pair of eyes perhaps shed light
Amny thanls