将LPTSTR p = s.GetBuffer( 2 ); 修改为:LPTSTR p = s.GetBuffer( 10 ); 测试结果同1。 测试3: 在测试二的LPTSTR p = s.GetBuffer( 10 );后添加 p[5]='f'; 测试结果同1。 测试4: 将测试三的p[5]='f';修改为p[4]='e'; 测试结果4: (1)before GetBuffer: CString s.length=4 CString ...
很明显ReleaseBuffer的作用就是更新字符串的长度。 CString内,GetLength获取字符串长度并不是动态计算的,而是在赋值操作后计算并保存在一个int变量内的,当通过GetBuffer直接修改CString时,那个int变量并不可能自动更新,于是便有了ReleaseBuffer. 示例:下面的例子说明了如何用CString::GetBuffer和CString::ReleaseBuffer(最好逐...
很多错误用法中最典型的一个就是CString:: GetBuffer ()了.查了MSDN,里面对这个operation的描述是: Returns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents。 这段很清楚的说明,对于这个operation返回...
将LPTSTR p = s.GetBuffer( 2 ); 修改为:LPTSTR p = s.GetBuffer( 10 ); 测试结果同1。 测试3: 在测试二的LPTSTR p = s.GetBuffer( 10 );后添加 p[5]='f'; 测试结果同1。 测试4: 将测试三的p[5]='f';修改为p[4]='e'; 测试结果4: (1)before GetBuffer: CString s.length=4 CString ...
LPTSTRGetBuffer(intnMinBufLength) 这个函数是CString 的一个比较实用的函数,请看如下示例: GetBuffer(int nMinBufLength);的参数问题一直比较困扰人,网站的资料还像也不是太好给的,请看msdn解释 Parameters nMinBufLength The minimum size of the character buffer in characters. This value does not include space...
CString的GetBuffer用法,GetBuffer本质,GetBuffer常质质 质解方法决 char*GetBuffer(n) 当n大于0质,是质CString质量分配一质度质个n的字质质,返回质是质质的地址数个数 当n等于0质,返回CString质量本身质有的字符串质的质数 ReleaseBuffer一般用在GetBuffer,因质在质用了GetBuffer后质量本身质自己上质,于是所有能会...
CString::GetBuffer LPTSTR GetBuffer( int nMinBufLength ); 返回值 一个指向对象的(以空字符结尾的)字符缓冲区的LPTSTR 指针。 参数 nMinBufLength 字符缓冲区的以字符数表示的最小容量。这个值不包括一个结尾的空字符的空间。 说明 此成员函数返回一个指向CString 对象的内部字符缓冲区的指针。返回的LPTSTR 不是...
// example for CString::GetBuffer CString s( "abcd" ); #ifdef _DEBUG afxDump << "CString s " << s << "\n"; #endif LPTSTR p = s.GetBuffer( 10 ); strcpy( p, "Hello" ); // directly access CString buffer s.ReleaseBuffer( ); #ifdef _DEBUG afxDump << "CString s " << s ...
There is also no reason to call CString::GetBuffer if you are not going to modify the string. The purpose of GetBuffer is to allow you to modify the string. You can use the cast to const char* that is built in to CString, or you can simply use token[i] to read a character in ...
ReleaseBufferbefore calling any other CString member functions.从MSDN的描述中可以知道,GetBuffer让我们获得CString对象字符内存的操作权,这样就可以操作CString对象了。但修改CString对象后,对象的状态信息并没有更新,于是便有了ReleaseBuffer。如果你之后需要继续使用该CString对象,就需要调用ReleaseBuffer。