MFC CString转化为char*

  • Post author:
  • Post category:其他



如题  CString转化为char*


char* str2char(CString str)


{




char *ptr;

#ifdef _UNICODE



LONG len;



len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);



ptr = new char[len + 1];



memset(ptr, 0, len + 1);



WideCharToMultiByte(CP_ACP, 0, str, -1, ptr, len + 1, NULL, NULL);

#else



ptr = new char[str.GetAllocLength() + 1];



sprintf(ptr, _T(“%s”), str);

#endif



return ptr;

}



版权声明:本文为l494926429原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。