读到U盘了? pch A pointer to an array of characters of length nLength, not null-terminated我只是开了一个64K个BYTE长度的CString而已啊。MSDN 上的例子: CAtlString s6( 'x', 6 ); // s6 = "xxxxxx"
我要指定长度是为了在后面调用GETBUFFER()进行数据拷贝的。
何必呢? 数据copy,就用CString.Fromat来做了,方便简单
不一定能分配那么大的空间啊……我想应该是这样的。 int nLength = str.GetLength(); 如果是2G的空间的话,不死才怪呢! 赫赫
CStringT inherits from CSimpleStringT Class. Advanced features, such as character manipulation, ordering, and searching, are implemented by CStringT.Note CStringT objects are capable of throwing exceptions. This occurs when a CStringT object runs out of memory for any reason.
CString strTest("" , nLen);
调用的是
CString(LPCSTR lpch, int nLength);
后面的参数表示lpch的长度,你这个""长度为0,你给了64K,都读到U盘了。
pch
A pointer to an array of characters of length nLength, not null-terminated我只是开了一个64K个BYTE长度的CString而已啊。MSDN 上的例子:
CAtlString s6( 'x', 6 ); // s6 = "xxxxxx"
数据copy,就用CString.Fromat来做了,方便简单
int nLength = str.GetLength();
如果是2G的空间的话,不死才怪呢!
赫赫
CString::CString(LPCTSTR lpch, int nLength)
{
Init();
if (nLength != 0)
{
ASSERT(AfxIsValidAddress(lpch, nLength, FALSE));
AllocBuffer(nLength);
memcpy(m_pchData, lpch, nLength*sizeof(TCHAR));
}
}
CString str('\0', 64 * 1024);
64k跨段了,什么意思,你以为还在DOS啊。
to ilovevc(ilovevc)
你写错了。
CString strTest("" , nLen);第一个参数LPCSTR长度为零,nLen有什么意思那,当然死了。
写成 CString strTest('1',64000)或者第一个参数LPCSTR长度为64k 就可以了。
CString strTest("" , 64000);这样有问题。我认为ilovevc的话没错。但我还是不太明白第一位兄弟所言:读到U盘了.
我想将CString初始化为hello,只要前面的5个字符,那么可以
CString str("hello,world", 5);
然后CString将从前面读5个字符,变成“hello",现在你给了一个"",实际长度算上结束字符才为1,然后欺骗CString说这个字符串至少有64k,那么就读出界了,也就是我说的都已经读到“u盘”了。
不是什么DOS不DOS的问题,ASSERT(AfxIsValidAddress(lpch, nLength, FALSE));这句话死了,因为从内存地址lpch开始后64k已经是???,就是无效地址了,关键在于搂主想用CString('', 64*1024)来构造CString, 却将''错写成了"",如果nLength小,那么从lpch开始的nLength这么长的地址空间都是应用程序自己的,就不会死,太大就死了