GetBuffer
Retrieve a pointer to the internal character buffer for the string.
char * GetBuffer( int nMinBufLength )
This is an LPTSTR pointer to the character buffer of the null-terminated object.
EX1
void string_GetBuffer_ex1() { string str = "abcdefg"; char *p = str.GetBuffer( 20 ); p[3] = 'D'; str.ReleaseBuffer(); out_str( str ); //output should be "abcDefg" }
EX2
void string_GetBuffer_ex1() { string str = "abcdefg"; char *p = str.GetBuffer(0); //no need to specify if we know we are not extending it p[3] = 'D'; str.ReleaseBuffer(); out_str( str ); //output should be "abcDefg" }
If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other string methods.
It is preferable to use GetBuffer(0) instead of GetBuffer(str.GetLength()).
string::ReleaseBuffer
origin.h