This snippet opens a file and inputs the number of records stored at the start; but then after that you will see I repeat the fstream allocation (without closing the original) and everything works exactly as it should.
However if I take this repeat fstream statement out it then doesn't output anything to the file - this I don't understand and it just doesn't seem right - is it - can anyone explain this to me?
Code:filename=filename+".txt"; fstream jcfile ( filename); if ( !jcfile.is_open() ) { cout<<endl<<endl<<endl<<"The file could not be opened."; } else { jcfile>>numrecords; cout<<endl<<endl<<endl<<"There are currently "<<numrecords<<" records in this file."; numrecords++; fstream jcfile (filename);// why is this needed jcfile.seekp (numrecords*20); jcfile<<"hello you sailor"; jcfile.seekp (0); jcfile<<numrecords; jcfile.close (); }



LinkBack URL
About LinkBacks


