Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference and the relationship of char and CString [duplicate]

Can someone explain me the difference and the relationship between the char * and CString?... Thanks.

like image 690
NULL_USER Avatar asked Oct 22 '25 04:10

NULL_USER


1 Answers

There are few important differences.

char * is a pointer to char. Generally you can't say if it a single char, or a beginning of a string, and what is the length. All those things are dictated by program logic and some conventions, i.e. standard C functions, like to use const char * as inputs. You need to manage memory allocated for strings manually.

CString is a macro. Depending on your program compilation options, it can be defined to either the CStringA or CStringW class. There are differences and similarities.

The difference is that CStringAoperates with non-Unicode data (similar to char*), and CStringW is a Unicode string (similar to wchar_t*).

Both classes, however, are equivalent in the aspect of string manipulation and storage management. They are closer to the standard C++ std::string and std::wstring classes.

Apart from that, both CStringA and CStringW provide the capability to convert strings to and from Unicode form.

like image 182
Valeri Atamaniouk Avatar answered Oct 23 '25 20:10

Valeri Atamaniouk