Click here to Skip to main content
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 3: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 OriginalGriff 431
1 Afzaal Ahmad Zeeshan 184
2 /\jmot 176
3 Sergey Alexandrovich Kryukov 175
4 Marcin Kozub 175
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 4 Apr 2013
Copyright © CodeProject, 1999-2014
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