Edit an existing file in C++ -


i have preferences file application in qt. whenever launch application loads file & depending contents creates widgets accordingly. have given customisation option user. when application closed checking whether preferences changed. if yes opening preferences file again & adding again in it. not creating temporary file, directly editing file. method efficient one? or doing wrong? because found these threads: 1. what best way edit middle of existing flat file?

  1. http://qt-project.org/forums/viewthread/25924/

should use binary file? using ascii file. thanks.

update: in stackoverflow link above correct answer has

if you're stuck using flat, you're stuck using old fashioned way of updating them

i meant ask whether method using old fashioned & there better method used nowadays? & flat file mean?

  1. don't try edit file. rewrite whole thing
  2. rewrite using temporary file. i.e. write current state of preferences temp file. , move/rename file actual preference file after making sure temp file has been written successfully. helps in case there crash when rewriting file. if rewrite directly, left neither old 1 nor new one. in case through temp file, way ensures in case of crash, atleast have preferences file(though contains old preferences).
  3. text/binary doesn't make difference unless it's huge file. text hand edit if required.

Comments