c++ - <Unable to read memory> while using fstream -
so i've been trying open file created, maintain getting error when seek open file. here debugger says:
std::basic_ios<char,std::char_traits<char> > = <unable read memory> basically happens first time run programme runs fine, sec time crashes when trying read file created. throws exception :
unhandled exception @ 0x012f1539 in project3.exe: 0xc0000005: access violation reading location 0x00000003.
here function throws exception:
int convert(string balance, int lineno){ // funciton convert strings in file ints--------------------------------- //getting info file locations int *pointer; pointer = findnewlines(); static int linenopos[11]; try{ (int = 0; < 11; i++){ linenopos[i] = *(pointer + i); } } grab (const std::exception& e){ std::cout << e.what() << std::endl; } int balanceint; seek { balancefile.open("e:\\moneystuff\\balance.txt", ios::in | ios::out); } grab (const std::exception& e) { std::cout << e.what() << std::endl; } //opening file balancefile.open("e:\\moneystuff\\balance.txt", ios::in | ios::out); //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; } and here function calls (just in case that's problem):
int * findnewlines(){ //function find \n characters in txt file---------------------------------------------- //creating variables function static int linenopos[11];//vector store line positions in char c; //variable checking character value int pos; //variable temporarily storing position int lineno = 0; //integer tell line read //writing in first line position linenopos[0] = 0; lineno++; balanceifile.open("e:\\moneystuff\\balance.txt", ios::binary); do{ balanceifile.get(c); if (c == '\n'){ pos = balanceifile.tellg(); linenopos[lineno] = pos; lineno++; } } while (balanceifile.good()); //resetting error flags balanceifile.clear(); homecoming linenopos; }
have tried taking out sec balancefile.open statement?
i include command statement if (balancefile) know you're reading data. if compile -g line number error on?
c++
No comments:
Post a Comment