can someone pls tell me what is wrong with my program
// the output is thisCode:#include <iostream> #include <fstream> using namespace std; int main() { fstream rfile; rfile.open("ITEMS.DAT", ios::in|ios::out); if(!rfile) { cout<<"error\n."; exit(1); } int c=0; cout<<"Enter c\n"; cin>>c; cin.get(); rfile.seekp(0, ios::end); rfile.write( (char*) (&c), sizeof(int) )<<flush; rfile.seekg(0, ios::beg); while (!rfile.eof()) { rfile.read( (char*) (&c), sizeof(int)); cout<<"c is:"<<c<<endl; } rfile.clear(); rfile.close(); return 0; }
//enter c
// c is:2
// c is:2
question: why are there two outputs of 2 even though the file is clean and i only enter one 2?



LinkBack URL
About LinkBacks


