当我尝试打开文件以阅读我的控制台应用程序时,出现此错误消息:“Homework1.exe中0x1048766d(msvcp90d.dll)未处理异常:0xC0000005:访问冲突写入位置0x00000000。 “当我在我的MacBook上编译和运行该程序时它工作正常,但是当我使用VS 2008在我的桌面上运行它时,它给了我这个错误。打开文件时出现C++错误
这里是我的代码:
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
代码标签似乎没有显示所有的代码,但它编译没有错误,所以我不知道发生了什么...... – cskwrd 2009-09-13 16:31:54
你能标记出引发异常的确切行吗? – mmmmmmmm 2009-09-13 16:32:45
'cout>文件名;'<---线应该是什么? – derobert 2009-09-13 16:36:15