CString str = "Florin"; // CString from char*
char * pcz = str.GetBuffer(); // char* from CString
str.ReleaseBuffer();
CString str2;
str2 = pcz; // CString from char*
CString str3 = "123";
int i = atoi(str3); // text number to int
long ln = atol(str3); // text number to long
But, instead of a char*, quite often you only need a (const char*) from a CString, and in those cases you can use the CString directly because it has a built in (LPCTSTR) operator. That is why atoi(str3) works.
Best Regards to you!
Dan
Florin Timariu wrote in message ...
GetBuffer() does not return char*, it returns LPTSTR which is char * only in
MBCS.
If it is UNICODE, you would can use macros like T2A (TCHAR to ASCII).
In addition, you dont want to call GetBuffer(), if you dont want to change
the contents of CString. Operator LPCTSTR is sufficient. Instead of atoi()
use _ttoi(), which would be good in all builds.
Ajay
Scott McPhillips wrote in message <36BF94AC...@REMOVEhome.com>...
>Florin Timariu wrote:
>>
>> how do i get char* from a CString.how do i form a CString when i have a
>> char* ? how about when CString represents a number? how do i convert it
to
>> int,or long.I tried casting but it didn't work for me.
>>
>> Best regards
>