A cstring variable CSTR
A char * variable ch
How to convert CSTR to ch?
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 (CSTR. 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 strlengh2 = cstr2.getlength () + 1;
Char charray [100];
Memset (charray, 0, sizeof (bool) * 100); // clears the junk content of the array.
Strncpy (charray, cstr2, strleng22 );
1. Convert string to cstring. format ("% s", String. c_str (); 2. Convert char * To cstring. format ("% s", char *); 3. Convert char * to string S (char *); 4. Convert string to char * P = string. c_str (); 5, cstring to string S (cstring. getbuffer (cstring. getlength (); 6. Convert cstring to char * charpoint = strtest. getbuffer (strtest. getlength (); it is not recommended to use (lpctstr) for forced type conversion, so that an error occurs when the strtest size changes. 7. Convert cstring to Char [100] char a [100]; cstring STR ("aaaaaa"); strncpy (A, (lpctstr) STR, sizeof ());
Attached: cstring-related member functions: http://www.cnblogs.com/Caiqinghua/archive/2009/02/16/1391190.html
Microsoft's summary: http://msdn.microsoft.com/zh-cn/library/vstudio/ms235631.aspx