对CString类中字符串的操作

能不能像操作字符数组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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值