Sunday, 8 September 2013

nocreate and noreplace flag


What do the nocreate and noreplace flag ensure when they are used for opening a file?

nocreate and noreplace are file-opening modes. A bit in the ios class defines these modes. The flag nocreate ensures that the file must exist before opening it. On the other hand the flag noreplace ensures that while opening a file for output it does not get overwritten with new one  unless ate or app is set. 

When the app flag is set then whatever we write gets appended to the existing file. When ate flag is set we can start reading or writing at the end of existing file.