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. Working with Files

Working with Files

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
2 Posts 2 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.
  • J Offline
    J Offline
    Jay Hova
    wrote on last edited by
    #1

    Hi, In my MFC app I need to read and write to a file. Write now I am working on the writing part of it all. I can write to a file that doesn't exist, but when the file does exists it always overwrites the contents of the file. I am using the following code:

    CStdioFile f;
    f.Open("test.txt",CFile::modeCreate | CFile::modeReadWrite | CFile::shareDenyWrite, NULL);
    f.WriteString(temp);
    f.Close();
    

    temp is just some string that the user enters. Can anyone tell me what I am doing wrong, and tell me how would i get it to append to the end when the file exists already? Is there a better way to do this?

    N 1 Reply Last reply
    0
    • J Jay Hova

      Hi, In my MFC app I need to read and write to a file. Write now I am working on the writing part of it all. I can write to a file that doesn't exist, but when the file does exists it always overwrites the contents of the file. I am using the following code:

      CStdioFile f;
      f.Open("test.txt",CFile::modeCreate | CFile::modeReadWrite | CFile::shareDenyWrite, NULL);
      f.WriteString(temp);
      f.Close();
      

      temp is just some string that the user enters. Can anyone tell me what I am doing wrong, and tell me how would i get it to append to the end when the file exists already? Is there a better way to do this?

      N Offline
      N Offline
      Navin
      wrote on last edited by
      #2

      Put this in the pot and see if it boils: f.Open("test.txt",CFile::modeCreate | **CFile::modeNoTruncate** | CFile::shareDenyWrite, NULL); Also, are you sure you need "modeReadWrite"? I doubt you'll ever need that for CStdioFile. "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein

      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