When fstream is used only with ios::out mode for an already existing file, it truncates the file and writes the data into the opened file afresh (as expected). But when fstream is used with both in and out modes as: fstream fil; fil.open("Student.dat",ios::out|ios::in); it does not truncate the already existing file, rather it overwrites on to the file which results in a file containing the new contents with some of the already existing contents appended to the new contents, while the 'out' mode is expected to truncate the already existing file. Can anybody please explain why that happens??
Aucun commentaire:
Enregistrer un commentaire