when I try to open a file for reading in my console application i get this error message: "Unhandled exception at 0x1048766d (msvcp90d.dll) in homework1.exe: 0xC0000005: Access violation writing location 0x00000000." It works fine when I compile and run the program on my macbook but when I run it on my desktop using VS 2008 it gives me this error.
here is my code:
int main (void){
//Open 1st file (baseproduct.dat)
ifstream fin;
//fin.open(filename.c_str());
fin.open("baseproduct.dat");
int tries;
tries = 0;
while( fin.bad() )
{
if( tries >= 4 )
{
cout > filename;
fin.open(filename.c_str());
tries++;
}
SodaPop inventory[100];
//read file into array
string strName;
double dblPrice;
int i;
i = 0;
fin >> strName;
while( !fin.eof() )
{
inventory[i].setName(strName);
fin >> dblPrice;
inventory[i].setPrice(dblPrice);
fin >> strName;
i++;
}
fin.close();
cout > filename;
//fin.open(filename.c_str());
fin.open("soldproduct.dat");
tries = 0;
while( fin.bad() )
{
if( tries >= 4 )
{
cout > filename;
fin.open(filename.c_str());
tries++;
}
//read file into array
i = 0;
fin >> strName;
while( !fin.eof() )
{
cout > dblPrice;
inventory[i].setPrice(dblPrice);*/
fin >> strName;
i++;
//1. search array for name
//2. get price (what should happen with it?)
//3. add # sold to quantity
}
fin.close();
cout