N
Neo
how convert CString to char *?
regards,
Mohammad Omer Nasir
regards,
Mohammad Omer Nasir
Neo said:how convert CString to char *?
regards,
Mohammad Omer Nasir
Mihai N. said:how convert CString to char *?
There are already 3 answers, all good, but depends what you need.
If you need a copy that you want to change, then go with new/_tcscpy [Bruno]
If you need to change the string in place, then GetBuffer() [Tom]
If you need read-only access to the buffer, then use implicit cast [David]
But I would like to add a special case: if the application is Unicode, then
the CString is also Unicode, meaning you don't get char*, but wchar_t*.
In this case David's code will not compile.
If you really need char* even for a Unicode application,
then you need to do a conversion to the (most likely) ANSI code page.
You can use WideCharToMultiByte or the T2A conversion macro.
But you have to make sure this is what you really need, because you will
damage all characters outside the code page used for conversion.