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. Unicode CString and fopen problem

Unicode CString and fopen problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelp
5 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.
  • D Offline
    D Offline
    DSPCottage
    wrote on last edited by
    #1

    Dear Experts Previously I could open a file by using following code snippet in Visual C++ 6 : CString fileName = "c:\\1.bin"; fopen(fileName,"wb"); But now I switched to visual C++ 2005 and activate unicode character set, but above code does not work. Please give a code snippet that I can use to feed a CString as a array of TCHAR to fopen function. Thanks Mahdi

    T J 2 Replies Last reply
    0
    • D DSPCottage

      Dear Experts Previously I could open a file by using following code snippet in Visual C++ 6 : CString fileName = "c:\\1.bin"; fopen(fileName,"wb"); But now I switched to visual C++ 2005 and activate unicode character set, but above code does not work. Please give a code snippet that I can use to feed a CString as a array of TCHAR to fopen function. Thanks Mahdi

      T Offline
      T Offline
      tagopi
      wrote on last edited by
      #2

      Hello, Since you set the property to Unicode Character Set, you can try like this.

          CString fileName = L"c:\\\\1.bin";
      CT2CA filen(fileName);
      fopen(filen,"wb");
      

      Hope this helps. Regards, A. Gopinath.

      D 1 Reply Last reply
      0
      • D DSPCottage

        Dear Experts Previously I could open a file by using following code snippet in Visual C++ 6 : CString fileName = "c:\\1.bin"; fopen(fileName,"wb"); But now I switched to visual C++ 2005 and activate unicode character set, but above code does not work. Please give a code snippet that I can use to feed a CString as a array of TCHAR to fopen function. Thanks Mahdi

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        Use the TCHAR version of fopen. Then the code can be used with Unicode and MBCS builds:

        CString fileName = _T("c:\\1.bin");
        _tfopen(fileName, _T("wb"));

        D 1 Reply Last reply
        0
        • T tagopi

          Hello, Since you set the property to Unicode Character Set, you can try like this.

              CString fileName = L"c:\\\\1.bin";
          CT2CA filen(fileName);
          fopen(filen,"wb");
          

          Hope this helps. Regards, A. Gopinath.

          D Offline
          D Offline
          DSPCottage
          wrote on last edited by
          #4

          Thanks , It works.

          1 Reply Last reply
          0
          • J Jochen Arndt

            Use the TCHAR version of fopen. Then the code can be used with Unicode and MBCS builds:

            CString fileName = _T("c:\\1.bin");
            _tfopen(fileName, _T("wb"));

            D Offline
            D Offline
            DSPCottage
            wrote on last edited by
            #5

            Thanks , it works perfect.

            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