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. CString

CString

Scheduled Pinned Locked Moved C / C++ / MFC
c++toolshelpquestion
7 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.
  • S Offline
    S Offline
    sidkraft
    wrote on last edited by
    #1

    C++ has several utilities to manipulate strings declared as char var;, i.e. strncpy(a,b,n); where a,b are strings, n is the number of characters, etc. However, when one declares a variable as a CString, and uses the same utility, the compiler says that it cannot convert the CString to a char variable. Are there other C++ or visual C++ 6.0 utilities to work with CString variables? Please provide help on this subject. Thanks, Sid Kraft

    Sid

    B T D 3 Replies Last reply
    0
    • S sidkraft

      C++ has several utilities to manipulate strings declared as char var;, i.e. strncpy(a,b,n); where a,b are strings, n is the number of characters, etc. However, when one declares a variable as a CString, and uses the same utility, the compiler says that it cannot convert the CString to a char variable. Are there other C++ or visual C++ 6.0 utilities to work with CString variables? Please provide help on this subject. Thanks, Sid Kraft

      Sid

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      When you need a const string you can use a CString directly. When it's being used in a non-const fashion, use CString::GetBuffer. char *strncpy( char *strDest, const char *strSource, size_t count ); (i.e. Here you can use CString as is for the second parameter since the LPCTSTR operator kicks in. If you use CString for the first parameter, you need it to be non-const. In other words, you need a buffer, so use CString::GetBuffer as the first parameter and later calling CString::ReleaseBuffer before calling any other CString member functions.)

      1 Reply Last reply
      0
      • S sidkraft

        C++ has several utilities to manipulate strings declared as char var;, i.e. strncpy(a,b,n); where a,b are strings, n is the number of characters, etc. However, when one declares a variable as a CString, and uses the same utility, the compiler says that it cannot convert the CString to a char variable. Are there other C++ or visual C++ 6.0 utilities to work with CString variables? Please provide help on this subject. Thanks, Sid Kraft

        Sid

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        cast it to (LPTSTR)(LPCTSTR)CString Object

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        M 1 Reply Last reply
        0
        • T ThatsAlok

          cast it to (LPTSTR)(LPCTSTR)CString Object

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
          Never mind - my own stupidity is the source of every "problem" - Mixture

          cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

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

          That has to be a joke.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

          T 1 Reply Last reply
          0
          • M Michael Dunn

            That has to be a joke.

            --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ I work for Keyser Söze

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            Michael Dunn wrote:

            That has to be a joke.

            thats the great mistake i have done!

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

            H 1 Reply Last reply
            0
            • T ThatsAlok

              Michael Dunn wrote:

              That has to be a joke.

              thats the great mistake i have done!

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              But why great mistake?;);P

              1 Reply Last reply
              0
              • S sidkraft

                C++ has several utilities to manipulate strings declared as char var;, i.e. strncpy(a,b,n); where a,b are strings, n is the number of characters, etc. However, when one declares a variable as a CString, and uses the same utility, the compiler says that it cannot convert the CString to a char variable. Are there other C++ or visual C++ 6.0 utilities to work with CString variables? Please provide help on this subject. Thanks, Sid Kraft

                Sid

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

                sidkraft wrote:

                However, when one declares a variable as a CString, and uses the same utility...

                And why in the world would you want to do that?

                sidkraft wrote:

                Are there other C++ or visual C++ 6.0 utilities to work with CString variables?

                They are called methods, and CString has plenty of them.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                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