Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert char array to CString? the CString should accept the NULL characters in it. char array contains the binary data.
Posted

Check this link for various conversion ->[^]
 
Share this answer
 
Comments
Albert Holguin 24-May-11 9:22am    
great resource
ShilpiP 25-May-11 0:24am    
Thanks :)
Sergey Alexandrovich Kryukov 24-May-11 16:23pm    
Agree, this is enough to answer. My 5.
--SA
ShilpiP 25-May-11 0:24am    
Thanks :)
rmds 26-Jan-19 8:37am    
The link goes to surface download page!!!
What about this,
TCHAR * p = _T("This is a test");
CString s = p;


Read this article for CString management,
CString Management[^]
 
Share this answer
 
v2
Comments
Doc Lobster 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.
Simply try this.

char caTemp[] = "Hello World";

CString sz = CString( caTemp );
 
Share this answer
 
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));
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900