c++ - Unhandled exception at 0x00C61540 in Project3.exe: 0xC0000005: Access violation reading location 0x00000003 -
i'm getting error whenever run programme sec time. writes info file, creating file if doesn't exist. however, when runs sec time, needs read created file, reason throws exception, , error:
unhandled exception @ 0x00c61540 in project3.exe: 0xc0000005: access violation reading location 0x00000003.
the debugger points line 15 in function getbalance place exception thrown. however, phone call function more once, , throws exception sec time phone call it.
int getbalance(int lineno){ // funciton convert strings in file ints string balance; //getting info file locations int *pointer; pointer = findnewlines(); static int linenopos[10]; (int = 0; < 11; i++){ linenopos[i] = *(pointer + i); } int balanceint; //opening file balancefile.open("e:\\moneystuff\\balance.txt", ios::in | ios::out); //exception thrown here //getting balances balancefile.seekg(linenopos[(lineno - 1)], ios::beg); getline(balancefile, balance); balancefile.close(); stringstream convert(balance);//variable convert string balance integer balance //converting balance string int convert >> balanceint; //setting balanceint 0 if file doesn't exist if (balanceint < -30000) balanceint = 0; homecoming balanceint; } edit: okay corrected part in code trying access element in array doesn't exist, i'm still getting same exception. exception seems happen when seek read created file, have permissions?
note: first time asking question here, if need give guys more code or more information, please tell me! thanks
when declare array 10 elements, means indexes goes 0 9.
adjust loop to:
for (int = 0; < 10; i++) trying access element doesn't exist in array cause weird behaviors, , crash 1 of them.
as exception caused open(), grab , print screen have clues of what's going on:
try { balancefile.open("e:\\moneystuff\\balance.txt", ios::in | ios::out); } grab (const std::exception& e ) { std::cout << e.what() << std::endl; } c++
No comments:
Post a Comment