如果去掉str.ReleaseBuffer();这行,就会显示234567811aaa 这是因为ReleaseBuffer()并不是释放整个Buffer,而是释放掉字符串后面无效的Buffer。 如果不执行,CString还是原来的长度,因为程序不清楚,分配的100这个大空间到底要用多少。 str += "aaa";这行为什么不自动计算长度,因为CString可以包含\0的, 比如用TCHAR *p =...
CString之GetBuffer与ReleaseBuffer 我们知道,CString是MFC中提供的方便字符串操作的一个类,非常好使,具有自动动态内存管理功能。 GetBuffer()主要作用是将字符串的缓冲区长度锁定; ReleaseBuffer()则是解除对缓冲区的锁定,这样使得CString对象在以后的代码中继续可以实现长度自适应增长的功能。 GetBuffer()说白了就两个功能...
CString::ReleaseBuffer voidReleaseBuffer(intnNewLength**=-1);** Parameters nNewLength The new length of the string in characters, not counting a null terminator. If the string is null-terminated, the -1 default value sets theCStringsize to the current length of the string. Remarks UseReleaseBuf...
在调用ReleaseBuffer之后,由GetBuffer返回的地址也许就无效了,因为其它的CString操作可能会导致CString缓冲区被重新分配。 如果你没有改变此CString的 MFC string char cstring 类型转换 ,z_cCurTime,z_len,NULL,NULL ); 1 前言 今天在网上看论坛,发现大家对CString与Char *互转各说一词,其实我发现提问者所说的情况...
CString之GetBuffer、ReleaseBufferLPTSTR GetBuffer( int nMinBufLength ); nMinBufLength为buffer的字符长度,不包括结束符 返回CString对象的内部buffer指针,非const,可以修改CString内容 void ReleaseBuffer( int nNewLength = -1 ); nNewLength为新的字符串长度,-1表示维持当前字符串长度 释放多余内存 注意点: ...
CString::ReleaseBuffer voidReleaseBuffer(intnNewLength**=-1);** Parameters nNewLength The new length of the string in characters, not counting a null terminator. If the string is null-terminated, the -1 default value sets theCStringsize to the current length of the string....
CString::ReleaseBuffer voidReleaseBuffer(intnNewLength**=-1);** Parameters nNewLength The new length of the string in characters, not counting a null terminator. If the string is null-terminated, the -1 default value sets theCStringsize to the current length of the string....
能不能在ReleaseBuffer()之前通过字符串赋值放大字符串缓冲,我是以vc2010重新测试得出的结论,在其他开发环境未测试。 不过还是认为,ReleaseBuffer()之前直接操作CString字符串对象虽然没有错误,但不合适,因为字符串已经通过GetBuffer()把控制权已经给出去,再去干涉内部缓冲区,明显忘记了调用GetBuffer()的目的和意义。
voidReleaseBuffer(intnNewLength**=-1);**ParametersnNewLengthThe new length of the string in characters, not counting a null terminator. If the string is null-terminated, the -1 default value sets the CString size to the current length of the string.Remarks...
s.ReleaseBuffer(); // 释放多余的内存,现在p 无效。 ASSERT( s.GetLength() == 3 ); // 长度仍然是3 CString::Remove int CString::Remove ( TCHAR ch ); 返回值 返回从字符串中移走的字符数。如果字符串没有改变则返回零。 参数 ch 要从一个字符串中移走的字符。