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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can i assign character array to cstring object

How can i assign character array to cstring object

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 Posts 5 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.
  • M Offline
    M Offline
    Mushtaque Nizamani
    wrote on last edited by
    #1

    Hi, I have a character array and want that to be assigned to cstring object, how can i do that. I have tried the assignment operator, but it is copying upto end line character, and leaving the other character. Does any one know about that? Warm Regards, Mushq

    P V A 3 Replies Last reply
    0
    • M Mushtaque Nizamani

      Hi, I have a character array and want that to be assigned to cstring object, how can i do that. I have tried the assignment operator, but it is copying upto end line character, and leaving the other character. Does any one know about that? Warm Regards, Mushq

      P Offline
      P Offline
      Paresh Chitte
      wrote on last edited by
      #2

      Look at the constructor of the CString class, CString( const unsigned char* psz ); throw( CMemoryException ); Regards, Paresh.

      1 Reply Last reply
      0
      • M Mushtaque Nizamani

        Hi, I have a character array and want that to be assigned to cstring object, how can i do that. I have tried the assignment operator, but it is copying upto end line character, and leaving the other character. Does any one know about that? Warm Regards, Mushq

        V Offline
        V Offline
        viral_umang hotmail com
        wrote on last edited by
        #3

        #include char str[30]; std::string temp; CString val; strcpy(str,"Hello"); temp=str; val.Empty(); val=temp.c_str(); Viral Joshi.

        M 1 Reply Last reply
        0
        • M Mushtaque Nizamani

          Hi, I have a character array and want that to be assigned to cstring object, how can i do that. I have tried the assignment operator, but it is copying upto end line character, and leaving the other character. Does any one know about that? Warm Regards, Mushq

          A Offline
          A Offline
          Arman S
          wrote on last edited by
          #4

          So you have a NULL inside your array. If it were possible what you want to do, CString wouldn't be a string class; A string should terminate with NULL symbol ('\0') to make itself be a string.

          -- ===== Arman

          1 Reply Last reply
          0
          • V viral_umang hotmail com

            #include char str[30]; std::string temp; CString val; strcpy(str,"Hello"); temp=str; val.Empty(); val=temp.c_str(); Viral Joshi.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            :omg: :wtf: That's sure a complicated way to do this: CString val; ... val = "Hello"; or CString val("Hello"); :) Are you paid by the line??

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            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