本站启用国内永久域名: www.LewenSky.cn,请大家使用新域名访问网站!
9月25

CString转char的方法总结

| |
16:43MFC/VC++  From: bizkit_room
1.传给未分配内存的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); //将数组的垃圾内容清空.

    strncpy(chArray, cstr1, strLength1);


出处:bizkit_room
转载时必须以链接形式注明出处及本声明!


最新日志 随机日志 综合排行
  • OFFICE 2010 VOL...
  • 格式工厂绿色版 V2.90
  • Password Invent...
  • VideoCacheView ...
  • 电脑店U盘启动盘制作工具 3....
  • 阿里旺旺AliIM2011_7...
  • 极点五笔十周年纪念版
  • PPTV网络电视3.1.1.0...
  • WinRAR注册方法
  • 紫光华宇拼音输入法 6.8.0...
  • CString常用方法简介
  • 迅雷 v5.9.24.1506...
  • XP与XP无线共享设置(笔记本...
  • 极品幽默!上帝都笑的满地找牙
  • 单文件打包工具Enigma_V...
  • 快车 FlashGet 3.2...
  • PPS网络电视 v2.7.0....
  • 论坛显示UID了 我的366 ...
  • 暴风影音2012_3.10.1...
  • OFFICE2003 SP3网...
  • 安装软件时出现系统提示&quo...
  • XP与XP无线共享设置(笔记本...
  • ZineMaker目录模板大集...
  • 没有不可能 轻松实现PDG转P...
  • CString转char的方法...
  • [转]MSDN精简版、MSDN...
  • 将IE、FIREFOR (火狐...
  • VC多线程编程(转)
  • MyEclipse6.5下载地...
  • Diskeeper 2010 ...
  • Tags: ,
    阅读(8905) | 评论(0) | 引用(0)
    发表评论
    表情
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    emotemotemotemotemot
    打开HTML
    打开UBB
    打开表情
    隐藏
    记住我
    昵称   密码   游客无需密码
    网址   电邮   [注册]