C++ Filehandling: Difference between ios::app and ios::ate?

前端 未结 5 1237
轻奢々
轻奢々 2020-11-28 06:13

What\'s the difference between ios::ate and ios:app when writing to a file.
In my view, ios::app gives you the ability to move aro

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-28 07:15

    It is pretty good documented here.

    ios::ate "sets the stream's position indicator to the end of the stream on opening."

    ios::app "set the stream's position indicator to the end of the stream before each output operation."

    This means the difference is that ios::ate puts your position to the end of the file when you open it. ios::app instead puts it at the end of the file every time you flush your stream. If for example you two programs that write to the same log file ios::ate will override anything that was added to the file by the other program since your program opened it. ios:app will instead jump to the end of file each time your program adds a log entry.

提交回复
热议问题