CString str("Hello World!"); LPCTSTR s = str.GetPointer(); printf("%s\n", s);
CString str("Sample Text"); TCHAR* buffer = str.GetBuffer(); strcat(buffer, " Appended Text!"); str.ReleaseBuffer();In this example, a CString object called "str" is created with the value "Sample Text". The GetBuffer method is then called on the object to retrieve a pointer to its internal character buffer. The std::strcat() function is then used to append a string " Appended Text!" to the buffer. Finally, the ReleaseBuffer method is called to release the buffer back to the CString object. Package library: MFC (Microsoft Foundation Class) library.