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











up vote
51
down vote

favorite
10












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 around in the file, whereas with ios::ate it can only read/write at the end of the file. Is this correct?










share|improve this question




























    up vote
    51
    down vote

    favorite
    10












    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 around in the file, whereas with ios::ate it can only read/write at the end of the file. Is this correct?










    share|improve this question


























      up vote
      51
      down vote

      favorite
      10









      up vote
      51
      down vote

      favorite
      10






      10





      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 around in the file, whereas with ios::ate it can only read/write at the end of the file. Is this correct?










      share|improve this question















      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 around in the file, whereas with ios::ate it can only read/write at the end of the file. Is this correct?







      c++ file fstream c++-standard-library






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jul 19 '16 at 12:57









      iammilind

      43.8k19122246




      43.8k19122246










      asked Apr 28 '12 at 1:12









      Adam_G

      2,170114592




      2,170114592
























          5 Answers
          5






          active

          oldest

          votes

















          up vote
          61
          down vote



          accepted










          It’s the other way around. When ios::ate is set, the initial position will be the end of the file, but you are free to seek thereafter. When ios::app is set, all output operations are performed at the end of the file. Since all writes are implicitly preceded by seeks, there is no way to write elsewhere.






          share|improve this answer




























            up vote
            30
            down vote













            They are specified as follows (in 27.5.3.1.4 of C++11):




            app seek to end before each write



            ate open and seek to end immediately after opening




            With ios::app the write position in the file is "sticky" -- all writes are at the end, no matter where you seek.






            share|improve this answer




























              up vote
              19
              down vote













              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 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 programm adds a log entry.






              share|improve this answer






























                up vote
                7
                down vote













                App:




                we cannot move the pointer.It will be only at end




                Ate:




                we can move the record pointer to any other place







                share|improve this answer




























                  up vote
                  0
                  down vote













                  The ios::ate option is for input and output operations and
                  ios::app allows us to add data to the end of file.






                  share|improve this answer























                  • Can you provide a link to documentation?
                    – harvpan
                    May 17 at 2:27










                  protected by Hovercraft Full Of Eels Nov 11 at 22:07



                  Thank you for your interest in this question.
                  Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                  Would you like to answer one of these unanswered questions instead?














                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  61
                  down vote



                  accepted










                  It’s the other way around. When ios::ate is set, the initial position will be the end of the file, but you are free to seek thereafter. When ios::app is set, all output operations are performed at the end of the file. Since all writes are implicitly preceded by seeks, there is no way to write elsewhere.






                  share|improve this answer

























                    up vote
                    61
                    down vote



                    accepted










                    It’s the other way around. When ios::ate is set, the initial position will be the end of the file, but you are free to seek thereafter. When ios::app is set, all output operations are performed at the end of the file. Since all writes are implicitly preceded by seeks, there is no way to write elsewhere.






                    share|improve this answer























                      up vote
                      61
                      down vote



                      accepted







                      up vote
                      61
                      down vote



                      accepted






                      It’s the other way around. When ios::ate is set, the initial position will be the end of the file, but you are free to seek thereafter. When ios::app is set, all output operations are performed at the end of the file. Since all writes are implicitly preceded by seeks, there is no way to write elsewhere.






                      share|improve this answer












                      It’s the other way around. When ios::ate is set, the initial position will be the end of the file, but you are free to seek thereafter. When ios::app is set, all output operations are performed at the end of the file. Since all writes are implicitly preceded by seeks, there is no way to write elsewhere.







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 28 '12 at 1:17









                      Jon Purdy

                      37.6k666125




                      37.6k666125
























                          up vote
                          30
                          down vote













                          They are specified as follows (in 27.5.3.1.4 of C++11):




                          app seek to end before each write



                          ate open and seek to end immediately after opening




                          With ios::app the write position in the file is "sticky" -- all writes are at the end, no matter where you seek.






                          share|improve this answer

























                            up vote
                            30
                            down vote













                            They are specified as follows (in 27.5.3.1.4 of C++11):




                            app seek to end before each write



                            ate open and seek to end immediately after opening




                            With ios::app the write position in the file is "sticky" -- all writes are at the end, no matter where you seek.






                            share|improve this answer























                              up vote
                              30
                              down vote










                              up vote
                              30
                              down vote









                              They are specified as follows (in 27.5.3.1.4 of C++11):




                              app seek to end before each write



                              ate open and seek to end immediately after opening




                              With ios::app the write position in the file is "sticky" -- all writes are at the end, no matter where you seek.






                              share|improve this answer












                              They are specified as follows (in 27.5.3.1.4 of C++11):




                              app seek to end before each write



                              ate open and seek to end immediately after opening




                              With ios::app the write position in the file is "sticky" -- all writes are at the end, no matter where you seek.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 28 '12 at 1:16









                              Steve Jessop

                              231k25365622




                              231k25365622






















                                  up vote
                                  19
                                  down vote













                                  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 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 programm adds a log entry.






                                  share|improve this answer



























                                    up vote
                                    19
                                    down vote













                                    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 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 programm adds a log entry.






                                    share|improve this answer

























                                      up vote
                                      19
                                      down vote










                                      up vote
                                      19
                                      down vote









                                      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 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 programm adds a log entry.






                                      share|improve this answer














                                      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 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 programm adds a log entry.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Mar 13 '16 at 13:41

























                                      answered Apr 28 '12 at 1:21









                                      Haatschii

                                      4,59883982




                                      4,59883982






















                                          up vote
                                          7
                                          down vote













                                          App:




                                          we cannot move the pointer.It will be only at end




                                          Ate:




                                          we can move the record pointer to any other place







                                          share|improve this answer

























                                            up vote
                                            7
                                            down vote













                                            App:




                                            we cannot move the pointer.It will be only at end




                                            Ate:




                                            we can move the record pointer to any other place







                                            share|improve this answer























                                              up vote
                                              7
                                              down vote










                                              up vote
                                              7
                                              down vote









                                              App:




                                              we cannot move the pointer.It will be only at end




                                              Ate:




                                              we can move the record pointer to any other place







                                              share|improve this answer












                                              App:




                                              we cannot move the pointer.It will be only at end




                                              Ate:




                                              we can move the record pointer to any other place








                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Sep 23 '13 at 10:14









                                              naveen

                                              8711




                                              8711






















                                                  up vote
                                                  0
                                                  down vote













                                                  The ios::ate option is for input and output operations and
                                                  ios::app allows us to add data to the end of file.






                                                  share|improve this answer























                                                  • Can you provide a link to documentation?
                                                    – harvpan
                                                    May 17 at 2:27















                                                  up vote
                                                  0
                                                  down vote













                                                  The ios::ate option is for input and output operations and
                                                  ios::app allows us to add data to the end of file.






                                                  share|improve this answer























                                                  • Can you provide a link to documentation?
                                                    – harvpan
                                                    May 17 at 2:27













                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  The ios::ate option is for input and output operations and
                                                  ios::app allows us to add data to the end of file.






                                                  share|improve this answer














                                                  The ios::ate option is for input and output operations and
                                                  ios::app allows us to add data to the end of file.







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited May 17 at 6:08









                                                  Jonathan Rys

                                                  1,136520




                                                  1,136520










                                                  answered May 17 at 2:03









                                                  toijam sonalika devi

                                                  1




                                                  1












                                                  • Can you provide a link to documentation?
                                                    – harvpan
                                                    May 17 at 2:27


















                                                  • Can you provide a link to documentation?
                                                    – harvpan
                                                    May 17 at 2:27
















                                                  Can you provide a link to documentation?
                                                  – harvpan
                                                  May 17 at 2:27




                                                  Can you provide a link to documentation?
                                                  – harvpan
                                                  May 17 at 2:27





                                                  protected by Hovercraft Full Of Eels Nov 11 at 22:07



                                                  Thank you for your interest in this question.
                                                  Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                  Would you like to answer one of these unanswered questions instead?



                                                  Popular posts from this blog

                                                  List item for chat from Array inside array React Native

                                                  Thiostrepton

                                                  Caerphilly