能不能像操作字符数组char a[n];中a指针那样对CString中的字符进行操作?能不能写操作?能不能读操作?怎样获得指向CString中字符的指针?
CString str ="sfdsf";
char *p=str.GetBuffer(0);
可以读写,但写入时,写入长度不能超过str.GetLength();否则,内存溢出出错<script language="VBScript" type="text/javascript"> call ReplaceSubjectHTML_tag(906350) </script>
CString str ="sfdsf";
str[0] = 'a';
跟char []一样用
CString a;
char b[10]="dcbaaaaa";
a="abcdefg";
//memcpy(b,a,a.GetLength()+1);//ok直接读取
//memcpy(b,a.GetBuffer(0),a.GetLength()+1);//ok,
memcpy(a.GetBuffer(0),b,a.GetLength());//ok
//memcpy(a,b,a.GetLength());
//报错:cannot convert parameter 1 from 'class CString' to 'void *'
//AfxMessageBox(b);
AfxMessageBox(a);
// get pointer to modifiable buffer at least as long as nMinBufLength
LPTSTR GetBuffer(int nMinBufLength);