首页 > 代码库 > mfc CString,string,char* 之间的转换
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;
mfc CString,string,char* 之间的转换
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。