码迷,mamicode.com
首页 > 编程语言 > 详细

mfc CString,string,char* 之间的转换

时间:2016-12-16 19:31:02      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:data   scp   string   lease   cstring   mfc   控件   转换   bsp   

知识点:
CString转char*,string
string转char*,CString
char* 转CString,string



一、CString转char*,string
    //字串转换测试
    CString CString1;
    std::string string1;
    CHAR*  char1=NULL;
    

    //1
    string1=CString1.GetBuffer();
    CString1.ReleaseBuffer();
    //2
    char1=CString1.GetBuffer();
    CString1.ReleaseBuffer();
二、string转char*,CString
    //1
    CString1=string1.data();
    //2
    char1=new CHAR[string1.length()+1];
    strcpy(char1,string1.data());

三、CHAR* 转CStringwstring
        CString1=char1;
             string1=char1;

    //// TODO: 在此添加控件通知处理程序代码
    //CString CString1="CString";
    //std::string string1="string";
    //CHAR * char1="char1";

    ////一、CString 字串转string ,char*
    //string1=CString1;
    //char1=CString1.GetBuffer();
    //CString1.ReleaseBuffer();//释放掉字串缓冲区

    ////二、string 转CString char*
    //string1="string1";
    //CString1=string1.data();
    ////char1=string1.data();
    //new char[string1.length()+1];
    //strcpy(char1,string1.data());
    ////三、char* 转CString ,string
    //char1="char1";
    //CString1=char1;
    //string1=char1;

    //// TODO: 在此添加控件通知处理程序代码
    //CString CString1=L"CString";
    //std::wstring string1=L"string";
    //WCHAR * char1=L"char1";

    ////一、CString 字串转string ,char*
    //string1=CString1;
    //char1=CString1.GetBuffer();
    //CString1.ReleaseBuffer();//释放掉字串缓冲区

    ////二、string 转CString char*
    //string1=L"string1";
    //CString1=string1.data();
    ////char1=string1.data();
    //new WCHAR[string1.length()+1];
    //wcscpy(char1,string1.data());
    ////三、char* 转CString ,string
    //char1=L"char1";
    //CString1=char1;
    //string1=char1;
 
    // TODO: 在此添加控件通知处理程序代码
    CString CString1=  _T("CString");
    std::string string1=_T("string");
    TCHAR * char1=_T("char1");

    //一、CString 字串转string ,char*
    string1=CString1;
    char1=CString1.GetBuffer();
    CString1.ReleaseBuffer();//释放掉字串缓冲区

    //二、string 转CString char*
    string1=_T("string1");
    CString1=string1.data();
    //char1=string1.data();
    new TCHAR[string1.length()+1];
    strcpy(char1,string1.data());
    //三、char* 转CString ,string
    char1=_T("char1");
    CString1=char1;
    string1=char1;

 

mfc CString,string,char* 之间的转换

标签:data   scp   string   lease   cstring   mfc   控件   转换   bsp   

原文地址:http://www.cnblogs.com/whzym111/p/6187772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!