cstring的长度
CString str = "hello";
int n = sizeof (str);
cout << "the size of str is :" << n << endl;
n = str.GetLength();
cout << "the length of str is :" << n << endl;
char *p1 = str.GetBuffer(str.GetLength()); //p1和str共享同一段内存
str.ReleaseBuffer();
strcpy(p1, "aa"); //将这个地方换成"aaaa","aaa","aaaaa"看看
cout << "the content of str is " << p1 << endl;
cout << "the content of p1 is " << p1 << endl;
n = sizeof (str);
cout << "the size of str is :" << n << endl;
n = str.GetLength();
cout << "the length of str is :" << n << endl;
为什么str.getlenth()的返回值老是5,不变呢?
还请大家多多指教,不胜感激.