CString::GetBufferSetLength Return Value An LPTSTR pointer to the object’s (null-terminated) character buffer.Parameters nNewLength The exact size of the CString character buffer in characters. CString str; LPTSTR pstr = str.GetBufferSetLength(3); pstr[0] = 'I'; pstr[1] = 'c'; pstr[2] = 'e';// No need for trailing zero or call to ReleaseBuffer() // because GetBufferSetLength() set it for us!str += _T(" hockey is best!");//MSDN CString
于是,我只想知道CString有没有这样的功能
{
CString(TCHAR* pX)
{
//取长度。
iLen = strlen(pX);
m_pData = new TCHAR[iLen];//MS可能不是这种方式。
}
private:
TCHAR* m_pData;//这个用来存储字符指针。
}
------------------------------------------------------这样的结构,还要什么设置缓冲区吗?MS的 cstring是不支持的。
LPTSTR pStr = str.GetBufferSetLength(nSize);
memcpy((void*)pStr,m_lpBufCur,nSize);
Return Value
An LPTSTR pointer to the object’s (null-terminated) character buffer.Parameters
nNewLength
The exact size of the CString character buffer in characters.
CString str;
LPTSTR pstr = str.GetBufferSetLength(3);
pstr[0] = 'I';
pstr[1] = 'c';
pstr[2] = 'e';// No need for trailing zero or call to ReleaseBuffer()
// because GetBufferSetLength() set it for us!str += _T(" hockey is best!");//MSDN CString
每次存,都会把原来的内存释放掉,开辟一块合适的内存
字符串用不好的话,后果很严重的。
但是如果是trace只有几百字节
str.GetBufferSetLength(10000);
这样就可以了啊
忘了,反正codeproject上有