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 can convert a char array to CString?

How can convert a char array to CString?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelptutorial
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.
  • L Offline
    L Offline
    Le rner
    wrote on last edited by
    #1

    Hi All, How can i convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,500); //reading some characters from the file CString str; how to store the charr array in to str? i m try this CString str(charr); but when i display a message box with str value its display only first character of charr. please help me for this. thanks in advance.

    C K C _ 4 Replies Last reply
    0
    • L Le rner

      Hi All, How can i convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,500); //reading some characters from the file CString str; how to store the charr array in to str? i m try this CString str(charr); but when i display a message box with str value its display only first character of charr. please help me for this. thanks in advance.

      C Offline
      C Offline
      Cool_Dev
      wrote on last edited by
      #2

      if this CString str(charr); doesn't work, then the problem may be with your character array. Does it contain what you expect?

      1 Reply Last reply
      0
      • L Le rner

        Hi All, How can i convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,500); //reading some characters from the file CString str; how to store the charr array in to str? i m try this CString str(charr); but when i display a message box with str value its display only first character of charr. please help me for this. thanks in advance.

        K Offline
        K Offline
        KingsGambit
        wrote on last edited by
        #3

        Check the encoding used in file.

        1 Reply Last reply
        0
        • L Le rner

          Hi All, How can i convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,500); //reading some characters from the file CString str; how to store the charr array in to str? i m try this CString str(charr); but when i display a message box with str value its display only first character of charr. please help me for this. thanks in advance.

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

          As already suggested by Rejeesh.T.S if your text file contains wide characters and your application doesn't use the UNICODE charset then the output posted is the expected result. Hence either make a UNICODE build or use MFC/ATL conversion macros in you project. :)

          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]

          1 Reply Last reply
          0
          • L Le rner

            Hi All, How can i convert a char array into CString? I have one array like this char charr[1000]; .... drwFile.Read(charr,500); //reading some characters from the file CString str; how to store the charr array in to str? i m try this CString str(charr); but when i display a message box with str value its display only first character of charr. please help me for this. thanks in advance.

            _ Offline
            _ Offline
            _Superman_
            wrote on last edited by
            #5

            You're probably not using a UNICODE build. You could either change Project -> Properties -> Configuration Properties -> General -> Character Set to Use Unicode Character Set or try using CStringW and MessageBoxW.

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++)

            Polymorphism in C

            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