Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. File Opening:

File Opening:

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T RATHA KRISHNAN
    wrote on last edited by
    #1

    I am trying to open a new file using Append mode in C++. But file is not opened. If I use out mode, file is opened.But the problem is: The data I entered once is lost during the next execution. I don't want the data to be lost. How to achieve this in C++. Is there any specific mode in C++ for this?

    S J H 3 Replies Last reply
    0
    • T T RATHA KRISHNAN

      I am trying to open a new file using Append mode in C++. But file is not opened. If I use out mode, file is opened.But the problem is: The data I entered once is lost during the next execution. I don't want the data to be lost. How to achieve this in C++. Is there any specific mode in C++ for this?

      S Offline
      S Offline
      Steve S
      wrote on last edited by
      #2

      You haven't said what you're using for file handling. Are you using WIN32 handles, stdio FILE*, or STD streams?

      Steve S Developer for hire

      T D 2 Replies Last reply
      0
      • T T RATHA KRISHNAN

        I am trying to open a new file using Append mode in C++. But file is not opened. If I use out mode, file is opened.But the problem is: The data I entered once is lost during the next execution. I don't want the data to be lost. How to achieve this in C++. Is there any specific mode in C++ for this?

        J Offline
        J Offline
        Jhony george
        wrote on last edited by
        #3

        open the file in apppend mode... syntax... modes for opening a file-----> fstream file_op("C:\\s1.txt ",ios::out|ios::app);

        T 1 Reply Last reply
        0
        • S Steve S

          You haven't said what you're using for file handling. Are you using WIN32 handles, stdio FILE*, or STD streams?

          Steve S Developer for hire

          T Offline
          T Offline
          T RATHA KRISHNAN
          wrote on last edited by
          #4

          fstream ofs("studfile.txt",ios::out); This is the statement I'm using to open the file. If I use app in place of out, the file is not opened. But I want the contents of the files don't get erased after each execution.

          D 1 Reply Last reply
          0
          • J Jhony george

            open the file in apppend mode... syntax... modes for opening a file-----> fstream file_op("C:\\s1.txt ",ios::out|ios::app);

            T Offline
            T Offline
            T RATHA KRISHNAN
            wrote on last edited by
            #5

            Thanks Mani. It's working.

            1 Reply Last reply
            0
            • S Steve S

              You haven't said what you're using for file handling. Are you using WIN32 handles, stdio FILE*, or STD streams?

              Steve S Developer for hire

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Steve S wrote:

              ...or STD streams?

              STL?


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              1 Reply Last reply
              0
              • T T RATHA KRISHNAN

                fstream ofs("studfile.txt",ios::out); This is the statement I'm using to open the file. If I use app in place of out, the file is not opened. But I want the contents of the files don't get erased after each execution.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                T.RATHA KRISHNAN wrote:

                If I use app in place of out...

                Why aren't you using both?


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                1 Reply Last reply
                0
                • T T RATHA KRISHNAN

                  I am trying to open a new file using Append mode in C++. But file is not opened. If I use out mode, file is opened.But the problem is: The data I entered once is lost during the next execution. I don't want the data to be lost. How to achieve this in C++. Is there any specific mode in C++ for this?

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  See CTextfile: A handy helper [^] does helpful?


                  WhiteSky


                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups