和老公感情淡了怎么办:CString类转换成char*(LPSTR)类型
来源:百度文库 编辑:中财网 时间:2024/05/11 04:54:39
Visual C++中的数据类型转换 发布于:软件开发网 来源:Duote 作者:佚名 时间:2011-09-25 22:55
若将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成员函数
VC编程中Cstring和char能互相转换吗,如果能怎么转换??
怎么把CString 转换成BYTE?
variant_t 类型怎么转换成CString
求vc++中CString类的常用函数列表(比如求子串,转换成整数类型等等)
CString与char字符数组怎么样才能相互转化使用?
java中 如何将char类型转换成string 类型
在C++中如何将INT转换成CHAR*类型?
char* to lpctstr类型转换
c语言 char类型转换
LPTSTR,LPCSTR,CString,LPCTSTR类型转换
int 与 CString 的转换问题
nt 与 CString 的转换问题
VC++中怎样将CString对象的值赋给字符型(char)数组?
c++中char类型变量如何转换成int类型变量?
java编程中,能否把char类型转换成String类型的值?
如何将int型的数字转换成char型字符串?
C++中如何把char[ ]类型转换成CTime类型?
c++如何转换char 到 int
请问int怎样转换到char?
C语言关于CHAR类型的转换
MFC的CString类的小问题
求VC++中CString类成员函数
VC 中的CString 类的使用困惑
c#里string 与char数组怎么转换