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. String convertion in c/c++?

String convertion in c/c++?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
10 Posts 7 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.
  • G Offline
    G Offline
    Gofur Halmurat
    wrote on last edited by
    #1

    Hello? Is there any way to convert:

    char* to const char*
    const char* to char*

    string to const string
    const string to string

    thanks in advance

    It is never late to learn

    S D S M 4 Replies Last reply
    0
    • G Gofur Halmurat

      Hello? Is there any way to convert:

      char* to const char*
      const char* to char*

      string to const string
      const string to string

      thanks in advance

      It is never late to learn

      S Offline
      S Offline
      sashoalm
      wrote on last edited by
      #2

      Could you be more specific? Please post the relevant code.

      There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

      1 Reply Last reply
      0
      • G Gofur Halmurat

        Hello? Is there any way to convert:

        char* to const char*
        const char* to char*

        string to const string
        const string to string

        thanks in advance

        It is never late to learn

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Yes.

        "Love people and use things, not love things and use people." - Unknown

        "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

        CPalliniC 1 Reply Last reply
        0
        • G Gofur Halmurat

          Hello? Is there any way to convert:

          char* to const char*
          const char* to char*

          string to const string
          const string to string

          thanks in advance

          It is never late to learn

          S Offline
          S Offline
          SandipG
          wrote on last edited by
          #4

          Cant you just type cast??

          Regards, Sandip.

          1 Reply Last reply
          0
          • G Gofur Halmurat

            Hello? Is there any way to convert:

            char* to const char*
            const char* to char*

            string to const string
            const string to string

            thanks in advance

            It is never late to learn

            M Offline
            M Offline
            Matthew Faithfull
            wrote on last edited by
            #5

            I think what you're looking for is const_cast e.g.char* pszData = "Letters and stuff."; const char* pszFixedText = const_cast< const char* >( pszData ); char* pszModifiable = const_cast< char* >( pszFixedText );

            "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

            M 1 Reply Last reply
            0
            • D David Crow

              Yes.

              "Love people and use things, not love things and use people." - Unknown

              "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

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

              People really don't like good answers. :)

              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.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              D 1 Reply Last reply
              0
              • CPalliniC CPallini

                People really don't like good answers. :)

                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.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                I was feeling generous. You know, I'm all for helping folks out of a jam, and even going the extra mile on occasion, but there comes a point when these posters have to grow up and start getting a clue. This next generation of developers is scaring me!

                "Love people and use things, not love things and use people." - Unknown

                "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

                CPalliniC 1 Reply Last reply
                0
                • D David Crow

                  I was feeling generous. You know, I'm all for helping folks out of a jam, and even going the extra mile on occasion, but there comes a point when these posters have to grow up and start getting a clue. This next generation of developers is scaring me!

                  "Love people and use things, not love things and use people." - Unknown

                  "The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch

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

                  Well, univoters are even worse: IMHO your answer is brilliant because (1) it is actually true. (2) enlights the inconsistency of the question. Univoting people cannot appreciate the above. :)

                  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.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  In testa che avete, signor di Ceprano?

                  1 Reply Last reply
                  0
                  • M Matthew Faithfull

                    I think what you're looking for is const_cast e.g.char* pszData = "Letters and stuff."; const char* pszFixedText = const_cast< const char* >( pszData ); char* pszModifiable = const_cast< char* >( pszFixedText );

                    "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

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

                    You don't need a cast to go from T* to const T*. And please don't suggest a cast for going from const T* to T* without knowing what the OP is actually doing. Teaching new C++ programmers that casts solve everything is really detrimental.

                    --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen

                    M 1 Reply Last reply
                    0
                    • M Michael Dunn

                      You don't need a cast to go from T* to const T*. And please don't suggest a cast for going from const T* to T* without knowing what the OP is actually doing. Teaching new C++ programmers that casts solve everything is really detrimental.

                      --Mike-- Visual C++ MVP :cool: LINKS~! CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen

                      M Offline
                      M Offline
                      Matthew Faithfull
                      wrote on last edited by
                      #10

                      Indeed, I didn't say this was good or recommended only that it was what he was looking for. In fact I'm no fan of the way const-ness is implemented in C++ at all and I don't take it nearly to the 'religious' extremes that some people do. I'd also prefer it if all type casts had to be explicitly implemented, even for builtin types but that's another issue. :)

                      "The secret of happiness is freedom, and the secret of freedom, courage." Thucydides (B.C. 460-400)

                      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