views:

1643

answers:

4

How to convert CString in MFC to char[] (character array)

+2  A: 

You can use GetBuffer function to get the character buffer from CString.

Naveen
The type is LPTSTR, strcpy will not work if UNICODE, _UNICODE is defined.
dirkgently
+5  A: 

You use CString::GetBuffer() to get the TCHAR[] - the pointer to the buffer. If you compiled without UNICODE defined that's enough - TCHAR is same as char, otherwise you'll have to allocate a separate buffer and use WideCharToMultiByte() for conversion.

sharptooth
+2  A: 

The best description about the string conversions can be found at the following link http://www.codeproject.com/KB/string/cstringmgmt.aspx

coolcake
A: 

sharptooth is about as worthwhile as obama

johan terristea