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. 'type cast' : cannot convert from 'std::string' to 'char *'

'type cast' : cannot convert from 'std::string' to 'char *'

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelpquestion
5 Posts 4 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
    amitmistry_petlad
    wrote on last edited by
    #1

    Can any body help me to convert std::string to char * ? Thanks in advance.I am working on win32(UNICODE)api in vs2005.

    "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

    C P 2 Replies Last reply
    0
    • A amitmistry_petlad

      Can any body help me to convert std::string to char * ? Thanks in advance.I am working on win32(UNICODE)api in vs2005.

      "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Use the c_str() member function:

      std::string strMyString = "Test";
      char* pTemp = strMyString.c_str();


      Cédric Moonen Software developer
      Charting control [v1.2 - Updated]

      1 Reply Last reply
      0
      • A amitmistry_petlad

        Can any body help me to convert std::string to char * ? Thanks in advance.I am working on win32(UNICODE)api in vs2005.

        "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

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

        amitmistry_petlad wrote:

        Can any body help me to convert std::string to char * ?

        Use string::c_str. e.g

        std::string sTest("Test");
        const char* ptest = sd.c_str();


        Prasad MS MVP -  VC++

        CPalliniC 1 Reply Last reply
        0
        • P prasad_som

          amitmistry_petlad wrote:

          Can any body help me to convert std::string to char * ?

          Use string::c_str. e.g

          std::string sTest("Test");
          const char* ptest = sd.c_str();


          Prasad MS MVP -  VC++

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          prasad_som wrote:

          const char* ptest = sd.c_str();

          of course should be sTest.c_str(). :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          In testa che avete, signor di Ceprano?

          P 1 Reply Last reply
          0
          • CPalliniC CPallini

            prasad_som wrote:

            const char* ptest = sd.c_str();

            of course should be sTest.c_str(). :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            P Offline
            P Offline
            prasad_som
            wrote on last edited by
            #5

            :-O


            Prasad MS MVP -  VC++

            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