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. CFile or CStdiofile : inserting text to begining of a existing file

CFile or CStdiofile : inserting text to begining of a existing file

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 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.
  • N Offline
    N Offline
    NILANKARAJA
    wrote on last edited by
    #1

    Hi, I want to add some text to the begining of a existing text file while keping its contents. I used SeekToBegin method but it overwrites the contents already in the file. Is there a way to do that?

    R H P 4 Replies Last reply
    0
    • N NILANKARAJA

      Hi, I want to add some text to the begining of a existing text file while keping its contents. I used SeekToBegin method but it overwrites the contents already in the file. Is there a way to do that?

      R Offline
      R Offline
      Raj Prathap
      wrote on last edited by
      #2

      I presume you can't do that! instead what u can do is open another temp file, and write the contents at the start of the temp file. and copy entire contents from the old file to temp file. After that replace old file by temp file. -- reddy

      N 1 Reply Last reply
      0
      • R Raj Prathap

        I presume you can't do that! instead what u can do is open another temp file, and write the contents at the start of the temp file. and copy entire contents from the old file to temp file. After that replace old file by temp file. -- reddy

        N Offline
        N Offline
        NILANKARAJA
        wrote on last edited by
        #3

        Yes, But what if the contents of the old file is really large. Will that be a problem in efficiency?

        R 1 Reply Last reply
        0
        • N NILANKARAJA

          Hi, I want to add some text to the begining of a existing text file while keping its contents. I used SeekToBegin method but it overwrites the contents already in the file. Is there a way to do that?

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

          See CTextFile: A handy helper[^] if its helpfuls


          WhiteSky


          1 Reply Last reply
          0
          • N NILANKARAJA

            Hi, I want to add some text to the begining of a existing text file while keping its contents. I used SeekToBegin method but it overwrites the contents already in the file. Is there a way to do that?

            P Offline
            P Offline
            priyeshtinku
            wrote on last edited by
            #5

            Open the file in different mode or flag

            1 Reply Last reply
            0
            • N NILANKARAJA

              Yes, But what if the contents of the old file is really large. Will that be a problem in efficiency?

              R Offline
              R Offline
              Raj Prathap
              wrote on last edited by
              #6

              u have to follow the same procedure even if the contents are very very large. Because except Xenix, no other OS provide insertion of bytes in the middle of the file, they support insertion only at the end of the file. -- reddy

              1 Reply Last reply
              0
              • N NILANKARAJA

                Hi, I want to add some text to the begining of a existing text file while keping its contents. I used SeekToBegin method but it overwrites the contents already in the file. Is there a way to do that?

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

                And also see here[^]


                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