MFC CString转换为字符数组
生活随笔
收集整理的这篇文章主要介绍了
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转换为字符数组的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: VC++实现汉明码
- 下一篇: C语言位运算实现加法