CString str("Hello, world!"); TCHAR* pBuf = str.GetBufferSetLength(7); // pBuf now points to a buffer containing "Hello,\0", // and str's length is set to 7
CString str("this is a test"); int len = str.GetLength(); // len == 14 TCHAR* pBuf = str.GetBufferSetLength(21); _tcscat_s(pBuf, 21, " of GetBufferSetLength"); str.ReleaseBuffer(); // str contains "this is a test of GetBufferSetLength"In this example, `GetLength` is used to determine the length of the original CString ("this is a test"), and then `GetBufferSetLength` is called with a length of 21 to ensure that enough space is available to append " of GetBufferSetLength" to the end of the string. The pointer returned by `GetBufferSetLength` is then used with `_tcscat_s` to concatenate the new string, and `ReleaseBuffer` is called to update the CString with the new data. Package library: MFC (Microsoft Foundation Classes)