string str="ksarea";
CString cstr(str.c_str());//或者CString cstr(str.data());初始化时才行
cstr=str.c_str();或者cstr=str.data();
str=cstr.GetBuffer(0); //CString -> string
cstr.format("%s", str.c_str()); //string->CString
cstr.format("%s", str.data()); //string->CString
str = LPCSTR(cstr); //CString->string
CString cstr(str.c_str());//或者CString cstr(str.data());初始化时才行
cstr=str.c_str();或者cstr=str.data();
str=cstr.GetBuffer(0); //CString -> string
cstr.format("%s", str.c_str()); //string->CString
cstr.format("%s", str.data()); //string->CString
str = LPCSTR(cstr); //CString->string

本文介绍了在C++中如何实现CString对象与string对象之间的相互转换。包括使用c_str()和data()方法初始化CString,以及利用GetBuffer方法从CString转换到string。
2017

被折叠的 条评论
为什么被折叠?



