当前位置: 代码迷 >> 综合 >> CString,string,char*,char a[100],int之间转换
  详细解决方案

CString,string,char*,char a[100],int之间转换

热度:16   发布时间:2024-01-04 20:38:25.0

 /*string->CString*/
 /* 
 string str;
 CString cstr;
 str="xiaowen";
 cstr.Format("%s",str.c_str());
 cout<<"str="<<str<<endl;  //输出xiaowen
 cout<<"cstr="<<cstr.GetBuffer (sizeof(CString))<<endl;  //输出xiaowen
 cout<<"cstr="<<cstr.GetBuffer (cstr.GetLength ())<<endl;  //输出xiaowen

 

 /*char*->CString*/
 /*
 char *p="xiaowen";
 CString cstr2;
 cstr2.Format ("%s",p);
 cout<<"p="<<p<<endl;  //输出xiaowen
 cout<<"cstr2="<<cstr2.GetBuffer (sizeof(CString))<<endl;  //输出xiaowen
 */

 

 /*string->const char* */
 /*
 string s2("xiaowen");
 const char *p=s2.c_str ();
 cout<<"p="<<p<<en

  相关解决方案