怎么样将一个CString类型转换为char[]的类型?

dc128 2003-11-13 10:39:36
如题~,求教~~
...全文
39 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluestone 2003-11-16
  • 打赏
  • 举报
回复
CString strString("hehehehe");
char szhehe[64];

memset(szhehe, 0, 64);
strcpy(szhehe, strString.operator LPCTSTR());

其实,strString.operator LPCTSTR()就是你要的东东了:)
lovenoend 2003-11-16
  • 打赏
  • 举报
回复
(LPCTSTR)str
CString 重载了(LPCTSTR)
ahfeng1980 2003-11-16
  • 打赏
  • 举报
回复
CString str;
char strTemp[n];
strcpy(strTemp,str);
lanstar200 2003-11-14
  • 打赏
  • 举报
回复
char szchar[50];
CString str="ascdefghijklmn";
strcpy(szchar , str.GetBuffer(str.GetLength()));
str.ReleaseBuffer();
0x191 2003-11-14
  • 打赏
  • 举报
回复
GetBuffer()
用完后再用ReleaseBuffer(),否则CString str就不会再被更新了
hq1978 2003-11-14
  • 打赏
  • 举报
回复
楼上的还调了一句,ReleaseBuffer (),否则以后用str就有问题了
CString str;
char strTemp[n];
memset(strTemp, 0, n);
memcpy(strTemp, str.GetBuffer(str.GetLength()), str.GetLength());
str.ReleaseBuffer();
xiaofei7569 2003-11-14
  • 打赏
  • 举报
回复
不要用sprintf
uoyevoli 2003-11-14
  • 打赏
  • 举报
回复
回复人: 0x191(我对程序过敏) ( ) 信誉:100 2003-11-14 10:03:00 得分:0


GetBuffer()
用完后再用ReleaseBuffer(),否则CString str就不会再被更新了


对!!!
yaoming2002 2003-11-13
  • 打赏
  • 举报
回复
CString str;
char strTemp[n];
memset(strTemp, 0, n);
memcpy(strTemp, str.GetBuffer(str.GetLength()), str.GetLength());
PiggyXP 2003-11-13
  • 打赏
  • 举报
回复
我一般都是用GetBuffer,没问题的
dc128 2003-11-13
  • 打赏
  • 举报
回复
不是char的指针,是一个char[]类型的数组~
MarginLi 2003-11-13
  • 打赏
  • 举报
回复
char *p = (char*)cstringTypeVar.GetBuffer(cstringTypeVar.GetLength());
ablefirst 2003-11-13
  • 打赏
  • 举报
回复
CString theString( "This is a test" );
LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString;
lshadow 2003-11-13
  • 打赏
  • 举报
回复
CString本来就支持[]操作符啊,如果你要转成char*可以用GetBuffer()
jEditor 2003-11-13
  • 打赏
  • 举报
回复
CString sChange = "sadgsdghsdhdshsdfj";
char *sBack;
sprintf(sBack, sChang);
........
flyelf 2003-11-13
  • 打赏
  • 举报
回复
sprintf

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧