1

When I write fout.open("file.dat",ios::out|ios::trunc|ios::binary); does the file loose all its data at that instance or it will wait for something to be written and then data will be lost? (I hope you get my point, all I'm asking is whether just writting the above statement, i.e fout.write() will invoke removal of records from a binary file or we need to pass some data to the file and then the previous data already stored in the file would be lost)

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
Keshav Sharma
  • 182
  • 2
  • 13

1 Answers1

2

The trunc flag will zero the file out at open().

codeDr
  • 1,535
  • 17
  • 20
  • you mean it will remove content of file just by typing fout.open() statement ? – Keshav Sharma Apr 01 '16 at 18:32
  • does it mean i can write fout.open ("file.dat" , ios::out|ios::trunc|ios::binary); fout.close(); like these 2 statement i can use em to delete content of file :) ? – Keshav Sharma Apr 01 '16 at 18:34
  • @Keshav Sharma `trunc` means truncate the existing contents to 0 bytes, so "yes" - see for example: http://www.cplusplus.com/doc/tutorial/files/ for documentation. – Jesper Juhl Apr 02 '16 at 15:41