Click here to Skip to main content
11,576,891 members (60,471 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC8.0
How to convert char array to CString? the CString should accept the NULL characters in it. char array contains the binary data.
Posted 24-May-11 2:06am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check this link for various conversion ->[^]
  Permalink  
Comments
Albert Holguin at 24-May-11 9:22am
   
great resource
SP 24 at 25-May-11 0:24am
   
Thanks :)
SAKryukov at 24-May-11 16:23pm
   
Agree, this is enough to answer. My 5.
--SA
SP 24 at 25-May-11 0:24am
   
Thanks :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What about this,
TCHAR * p = _T("This is a test");
CString s = p;

Read this article for CString management,
CString Management[^]
  Permalink  
v2
Comments
Doc Lobster at 25-May-11 0:03am
   
This won't do for 0-characters in the input string as they would be recognized as string terminator. It probably would help providing the input buffer length as second parameter to the CString contructor. BTW, help in the msdn is provided for the CStringT template, not for CString itself.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If your CString should contain the exact binary copy of the character array (however, what is the purpose of such a requirement?) then you have to use GetBuffer/ReleaseBuffer methods, for instance:

char p[] = {0x10,0x41, 0x00, 0x45};
CStringA foo;
memcpy(foo.GetBufferSetLength(sizeof(p)), p, sizeof(p));
foo.ReleaseBuffer(sizeof(p));
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Simply try this.

char caTemp[] = "Hello World";

CString sz = CString( caTemp );
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 221
1 DamithSL 155
2 Abhinav S 130
3 OriginalGriff 95
4 Lucifier Rocks 85
0 OriginalGriff 715
1 Sergey Alexandrovich Kryukov 631
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100