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 Convert CString to Char*

How to Convert CString to Char*

Scheduled Pinned Locked Moved C / C++ / MFC
helpcomtutorial
6 Posts 6 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
    pathi
    wrote on last edited by
    #1

    Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com

    N C C C 4 Replies Last reply
    0
    • P pathi

      Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      CString str("Some string"); char* chr = (char*)(const char*)str; I vote pro drink :beer:

      M 1 Reply Last reply
      0
      • P pathi

        Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You can create a CString from a char*, and to go back do this CString s; s.GetBuffer(s.GetLength()+1); s.ReleaseBuffer(); Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

        1 Reply Last reply
        0
        • N Nemanja Trifunovic

          CString str("Some string"); char* chr = (char*)(const char*)str; I vote pro drink :beer:

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          That will break if the contents of str are modified. GetBuffer() is the right way to get a non-const pointer to the string. --Mike-- http://home.inreach.com/mdunn/ Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese? Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say?

          1 Reply Last reply
          0
          • P pathi

            Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com

            C Offline
            C Offline
            CodeGuy
            wrote on last edited by
            #5

            Also, if you just need to pass a const char* to a CRT/WinAPI function, you can use CString s = "a string"; CallMyCharFunction((LPCTSTR)s); But if you really need a char* , use the methods above. CodeGuy The WTL newsgroup: 910 members and growing ... http://groups.yahoo.com/group/wtl

            1 Reply Last reply
            0
            • P pathi

              Hi, Iam getting problem with converting CString into Char* and vise versa. If anyone helps me in this thanks for their help. Regards Pathi bhikshapathi_g@semanticspace.com

              C Offline
              C Offline
              Carlos Antollini
              wrote on last edited by
              #6

              strcpy(szstr, str.GetBuffer()); //where str is a CString and szstr is a char* Cheers!!! Carlos Antollini.

              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