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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to overwrite the CString in the CFile

How to overwrite the CString in the CFile

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 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.
  • A Offline
    A Offline
    anilksingh
    wrote on last edited by
    #1

    we are writting the CString data in to the file using CFile. first time we are able to write the data correctly but from second time data is not overwritten. even if we remove the file , the file is generatted with same data.If any one have Idea how this prob can solved please give me. (CFile::modeCreate | CFile::modeWrite)

    R _ V M 4 Replies Last reply
    0
    • A anilksingh

      we are writting the CString data in to the file using CFile. first time we are able to write the data correctly but from second time data is not overwritten. even if we remove the file , the file is generatted with same data.If any one have Idea how this prob can solved please give me. (CFile::modeCreate | CFile::modeWrite)

      R Offline
      R Offline
      Rajesh R Subramanian
      wrote on last edited by
      #2

      Can you please post the code? Being a computer, I find your faith in the technology to be amazing. But sorry, you dont have the right to issue this command!

      1 Reply Last reply
      0
      • A anilksingh

        we are writting the CString data in to the file using CFile. first time we are able to write the data correctly but from second time data is not overwritten. even if we remove the file , the file is generatted with same data.If any one have Idea how this prob can solved please give me. (CFile::modeCreate | CFile::modeWrite)

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        Read the data from the file and write to temproary file. Delete the file you were reading the data from. Rename the temproary file. Somethings seem HARD to do, until we know how to do them. ;-) _AnShUmAn_

        1 Reply Last reply
        0
        • A anilksingh

          we are writting the CString data in to the file using CFile. first time we are able to write the data correctly but from second time data is not overwritten. even if we remove the file , the file is generatted with same data.If any one have Idea how this prob can solved please give me. (CFile::modeCreate | CFile::modeWrite)

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          Probably the second time the CString objects contain the same values as for the first time. You should check if the CString data really contain information you expect before writting to file.

          1 Reply Last reply
          0
          • A anilksingh

            we are writting the CString data in to the file using CFile. first time we are able to write the data correctly but from second time data is not overwritten. even if we remove the file , the file is generatted with same data.If any one have Idea how this prob can solved please give me. (CFile::modeCreate | CFile::modeWrite)

            M Offline
            M Offline
            Mark F
            wrote on last edited by
            #5

            Do you have error checking in place?

            CString str;          // or whatever you have
            CFile pFile;
            CFileException ex;    // add exception handling
            char szError[255];    // add msg buffer
            
            if( !pFile.Open(szFile, CFile::modeCreate|CFile::modeWrite, &ex) )
            {
               ex.GetErrorMessage(szError, 255, NULL);
               AfxMessageBox("File Error: " + szError, MB_OK|MB_ICONERROR);
               return;   // or return FALSE;
            }
            
            if( !str.IsEmpty() )  // always check for data!
            { 
              // Now write the data to file...
              pFile.Write((LPCTSTR)str, str.GetLength());
            }
            
            // close
            pFile.Close();
            

            HTH Mark

            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