In VC, cstring classes have various usage forms and are rich and colorful, but sometimes the conversion from traditional data types has become a challenge for many people.
Next I will briefly introduce the relationships between them.
1. How to convert cstring to char:
Cstring m_cstr = "ABC ";
Char * m_char = "def ";
Char * Lp = M_cstr.getbuffer (m_cstr.getlength ());
M_cstr.releasebuffer ();
// Convert the opposite char * To cstring
M_cstr.format ( " % S " , LP); // LP is an array pointer
Type 2: Forced type conversion to lpctstr
Lptstr P = M_cstr.getbuffer ( 10 );
Strcpy (count, P ); M_cstr.releasebuffer ();
2. Conversion between cstring and byte
Byet is unsigned character type. The principle is similar to that of char.
Cstring m_cstr;
Byte m_byte [ 100 ];
M_byte = (Byte * ) M_cstr.getbuffer (m_cstr.getlength ()); // Cstring to byte
Likewise:
M_cstr.format ( " % S " , M_byte ); // Byte string output
3 Conversion between byte and char type
Strcpy and memcpy functions can be forcibly converted.
Strcpy (m_char, (char *) m_byte );
Strlen = (char *) m_byet;
memcpy (m_char, m_byte, strlen);