GetBuffer and ReleaseBuffer体会

 

CString s( "abcd" );
#ifdef _DEBUG
afxDump << "CString s " << s << "/n";
#endif
LPTSTR p = s.GetBuffer( 100);   //means 开辟的buffer的size.
strcat( p, "Hello" );   // directly access CString buffer
s.ReleaseBuffer(-1);     //改变了字符串内容,务必调用ReleaseBuffer.使p无效.
#ifdef _DEBUG
afxDump << "CString s " << s << "/n";
afxDump << "CString s " << s.GetLength() << "/n";
#endif

output:

CString s abcd
CString s abcdHello
CString s 9 

你可能感兴趣的:(GetBuffer and ReleaseBuffer体会)