软件注册站
热情软件屋

 
如何将CString类型的变量赋给char*类型的变量
编号: QA002101    
建立日期: 1999年11月25日 最后修改日期: 2004年1月1日
所属类别: C/C++ - 其他方面
   
    操作系统: windows98
    编程工具: VC++6.0
    问题: 请问如何将CString类型的变量赋给char*类型的变量?(john)
   
    Lu Tao的意见:
     CString Msg;
    
Msg=Msg+"abc";
    
LPTSTR lpsz;
    
lpsz = new TCHAR[Msg.GetLength()+1];
    
_tcscpy(lpsz, Msg);
    
char * psz;
    
strcpy(psz,lpsz);
    

    
    doublehu的意见:
    char *ch;
    CString str;
    ch=(LPSTR)(LPCTSTR)str;
    
    陈啸龙的意见:
    CString mCS=_T("cxl");
    char mch[20];
    memcpy(mch,mCS,20);
    
    李海、阿进的意见:
    使用CString::GetBuffer函数。例子:
    char *p;
    
CString str("hello");
    
p=str.GetBuffer(str.GetLength());
    
    

    榕溶的意见:
    CString aaa="aaa";
    char *ch
    ch=aaa.c_str;
    
    相关问题:
    QA002733 "WriteFile函数中的字符数组能否用CString对象来替代"
    
    longbow问: 反过来怎么办?即如何将char*类型的变量赋给cstring型的变量?
    李海:这很容易,可以直接赋值,如:
    CString myString = "This is a test";
    也可以利用构造函数,如:
    CString s1( "Tom" );

    

此问题由Lu Tao等回答。

附加关键字:编程, 源程序, programming, source code, C/C++, MFC, C++ Builder, Borland C++, Turbo C, C, BCB, 其他方面,

   
 
把这个问题推荐给朋友
   
 
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio