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. how to write a CString object into a file?

how to write a CString object into a file?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 3 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.
  • P Offline
    P Offline
    P_JAYAPRAKASH
    wrote on last edited by
    #1

    Hai i would like to know how to write a CString object into file; Please help me!! Thanks JP

    A A 2 Replies Last reply
    0
    • P P_JAYAPRAKASH

      Hai i would like to know how to write a CString object into file; Please help me!! Thanks JP

      A Offline
      A Offline
      alex barylski
      wrote on last edited by
      #2

      You can use MFC serialization or you can do it directly using MFCC File object

      CFile myFile('test.dat', CFile::modeWrite);

      CString buff;
      buff = "This is some text";

      myFile.Write(buff, buff.GetLength());

      p.s- you can also use Windows SDK functions or the CRT functions so your code works on all platforms (most anyways) HTH Cheers :) The word of the day is legs, let's go back to my house and spread the word ;P

      P 1 Reply Last reply
      0
      • A alex barylski

        You can use MFC serialization or you can do it directly using MFCC File object

        CFile myFile('test.dat', CFile::modeWrite);

        CString buff;
        buff = "This is some text";

        myFile.Write(buff, buff.GetLength());

        p.s- you can also use Windows SDK functions or the CRT functions so your code works on all platforms (most anyways) HTH Cheers :) The word of the day is legs, let's go back to my house and spread the word ;P

        P Offline
        P Offline
        P_JAYAPRAKASH
        wrote on last edited by
        #3

        hi Thanks for ur reply.Did u check this code,since it is not working. Thanks JP

        A 1 Reply Last reply
        0
        • P P_JAYAPRAKASH

          hi Thanks for ur reply.Did u check this code,since it is not working. Thanks JP

          A Offline
          A Offline
          alex barylski
          wrote on last edited by
          #4

          Typically code I write here on CP is psuedo code, just to get you started on the right direction, I hardly never test code. try this instead:

          CFile myFile('test.dat', CFile::modeWrite);
          CString buff;
          buff = "This is some text";
          myFile.Write(buff.GetBuffer(buff.GetLength()), buff.GetLength());

          The word of the day is legs, let's go back to my house and spread the word ;P

          1 Reply Last reply
          0
          • P P_JAYAPRAKASH

            Hai i would like to know how to write a CString object into file; Please help me!! Thanks JP

            A Offline
            A Offline
            Abhishek Srivastava
            wrote on last edited by
            #5

            Try to write like this! CFile myFile('test.dat', CFile::modeWrite); CString buff; buff = "This is some text"; myFile.Write(str.operator LPCTSTR(),buff.GetLength()); :) Abhishek Srivastava Software Engineer (VC++) India ,Noida Mobile no 9891492921 :)

            P 1 Reply Last reply
            0
            • A Abhishek Srivastava

              Try to write like this! CFile myFile('test.dat', CFile::modeWrite); CString buff; buff = "This is some text"; myFile.Write(str.operator LPCTSTR(),buff.GetLength()); :) Abhishek Srivastava Software Engineer (VC++) India ,Noida Mobile no 9891492921 :)

              P Offline
              P Offline
              P_JAYAPRAKASH
              wrote on last edited by
              #6

              hi Thanks for ur solution!! But if u use above code..it is not giving any error while executing..but this writes our data with some junk value...So we can't retrieve it properly. Cheers JP:)

              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