CString转换指针
2016-07-15 20:39
246 查看
.传给未分配内存的const char* (LPCTSTR)指针. CString cstr(asdd); const char* ch = (LPCTSTR)cstr; ch指向的地址和cstr相同。但由于使用const保证ch不会修改,所以安全. 2.传给未分配内存的指针. CString cstr = "ASDDSD"; char *ch = cstr.GetBuffer(cstr1.GetLength() + 1); cstr.ReleaseBuffer(); //修改ch指向的值等于修改cstr里面的值. //PS:用完ch后,不用delete ch,因为这样会破坏cstr内部空间,容易造成程序崩溃. 3.第二种用法。把CString 值赋给已分配内存的char *。 CString cstr1 = "ASDDSD"; int strLength = cstr1.GetLength() + 1; char *pValue = new char[strLength]; strncpy(pValue, cstr1, strLength); 4.第三种用法.把CString 值赋给已分配内存char[]数组. CString cstr2 = "ASDDSD"; int strLength1 = cstr1.GetLength() + 1; char chArray[100]; memset(chArray,0, sizeof(bool) * 100); //将数组的垃圾内容清空.
相关文章推荐
- 华为OJ——放苹果
- ulua热更新小demo
- 欢迎使用CSDN-markdown编辑器
- 13.You have executed this command to change the size of the database buffer cache:
- 华为OJ——查找组成一个偶数最接近的两个素数
- Linux基础(14)Linux的特殊权限
- 30行代码实现JavaScript中的MVC
- 第一次写博客
- iOS开发—自定义按钮
- 笨办法学python 42
- HDU Today---hdu2112(最短路-_-坑在是无向图)
- 华为OJ——找出字符串中第一个只出现一次的字符
- JavaScript中this指针指向的彻底理解
- java当中类和对象
- UVA 133 The Dole Queue
- atoi---ASCII to integer,将字符串转换成整形,经常用的转换符号
- 在C#中 ref和out的区别
- LeetCode---2.StringEasy
- 华为OJ——输入n个整数,输出其中最小的k个
- RxJava源码分析