欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

MFC CString转换为字符数组

发布时间:2025/4/14 编程问答 45 豆豆
生活随笔 收集整理的这篇文章主要介绍了 MFC CString转换为字符数组 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

VC6单文档工程;

void CZfszView::OnDraw(CDC* pDC) {CZfszDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data here//char sendBuf[256];//CString sendStr = "xxx"; //sprintf_s(sendBuf, sizeof(sendStr), (const char*)&sendStr);//数据到sendBuf//sprintf(sendBuf, sizeof(sendStr), (const char*)&sendStr);//数据到sendBuf//char ch[20];//CString str="abcd";//strcpy(ch,CW2A(str));CString str="hello!"; pDC->TextOut(50,50,str);char ch[6]; memcpy(ch,str,str.GetLength()); pDC->TextOut(50,80,ch);}

前面注释了的2段来自网上;均会出错;使用memcpy可以实现;

 

总结

以上是生活随笔为你收集整理的MFC CString转换为字符数组的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。