VC新手:CString字串如何转为char字串或啊!多谢! 如题! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接用就可以了吧,或者用强制类型转换(char *)不可以吗? 转贴:CString转换成char* 若将CString类转换成char*(LPSTR)类型,常常使用下列三种方法: 方法一,使用强制转换。例如:CString theString( "This is a test" );LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString; 方法二,使用strcpy。例如:CString theString( "This is a test" );LPTSTR lpsz = new TCHAR[theString.GetLength()+1];_tcscpy(lpsz, theString); 需要说明的是,strcpy(或可移值Unicode/MBCS的_tcscpy)的第二个参数是 const wchar_t* (Unicode)或const char* (ANSI),系统编译器将会自动对其进行转换。 方法三,使用CString::GetBuffer。例如:CString s(_T("This is a test "));LPTSTR p = s.GetBuffer();// 在这里添加使用p的代码if(p != NULL) *p = _T('\0');s.ReleaseBuffer(); // 使用完后及时释放,以便能使用其它的CString成员函数 cstring str;char chValue[128];strcpy(chValue, str.GetBuffer(str.GetLength()), str.GetLength()); CListCtrl中怎样才能多行显示呢? 用DirectSound枚举声音设备,在Windows7中枚举不到我的设备 VC中怎么获取文件的路径? 高手请进,多线程winsock程序的问题(高分-在线等) 刚才经理过来看我在冲奶,说:你喝白开水不行啊,冲奶多耽误时间,赶紧抓紧时间工作,你看别人都工作呢,就你闲着。MaBiDe没给气死,现在 如何关闭安装驱动程序时产生的一些窗口? 请教一个常识问题 如何在命令行下注册.ocx控件 求助:MFC oxc中使用PictureEx的问题 这里CString和string的区别 GUID怎样生成?? CreateProcess 不成功
LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString; 方法二,使用strcpy。例如:CString theString( "This is a test" );
LPTSTR lpsz = new TCHAR[theString.GetLength()+1];
_tcscpy(lpsz, theString); 需要说明的是,strcpy(或可移值Unicode/MBCS的_tcscpy)的第二个参数是 const wchar_t* (Unicode)或const char* (ANSI),系统编译器将会自动对其进行转换。 方法三,使用CString::GetBuffer。例如:CString s(_T("This is a test "));
LPTSTR p = s.GetBuffer();
// 在这里添加使用p的代码
if(p != NULL) *p = _T('\0');
s.ReleaseBuffer();
// 使用完后及时释放,以便能使用其它的CString成员函数
char chValue[128];strcpy(chValue, str.GetBuffer(str.GetLength()), str.GetLength());