1. Pass the const char * (lpctstr) pointer to the unallocated memory.
Cstring CSTR (asdd );
Const char * Ch = (lpctstr) CSTR;
Ch points to the same address as CSTR. However, since the use of const ensures that CH will not be modified, it is safe.
2. Pass the pointer to the unallocated memory.
Cstring CSTR = "asddsd ";
Char * Ch = CSTR. getbuffer (cstr1.getlength () + 1 );
CSTR. releasebuffer ();
// Modify the value that CH points to is equal to the value in CSTR.
// PS: After the CH is used up, the delete ch is not used, because this will destroy the internal space of CSTR and cause program crash.
3. Second usage. Assign the cstring value to the char * of the allocated memory *.
Cstring cstr1 = "asddsd ";
Int strlength = cstr1.getlength () + 1;
Char * pvalue = new char [strlength];
Strncpy (pvalue, cstr1, strlength );
4. Method 3: Assign the cstring value to the allocated memory char [] array.
Cstring cstr2 = "asddsd ";
Int strlength1 = cstr1.getlength () + 1;
Char charray [100];
Memset (charray, 0, sizeof (bool) * 100); // clears the junk content of the array.
Strncpy (charray, cstr1, strlength1 );