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


    知识点:
    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;
  • 相关阅读:
    异步模型
    Netty模型
    Reactor 模式-3 种典型实现
    线程模型基本介绍
    IDEA引入Netty包
    NIO中的零拷贝
    基于NIO实现后台简易群聊系统
    Selector选择器
    DevOps之Pipeline集成junit、jacoco、SonarQube(二)
    Python基础(四)
  • 原文地址:https://www.cnblogs.com/whzym111/p/6187772.html
Copyright © 2020-2023  润新知