Re: CString to const char*
- From: "Abdo Haji-Ali" <ahali@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 15:43:59 +0200
"NickP" <a@xxxxx> wrote in message
news:eHvzYzi4GHA.4256@xxxxxxxxxxxxxxxxxxxxxxx
For some reason it will not convert to const char* automatically, if I0
try manually I just end up with a screwed up ASCII string still containing
bytes from the UNICODE equivilent.Remember that there are two versions of CString: CStringA and CStringW.
Which one is used depends on whether UNICODE is defined or not...
char *pBuffer = new char[iString.GetLength()];GetBuffer() would return "const wchar_t*" (since UNICODE is defined) not
pBuffer = (char*)iString.GetBuffer(sizeof(pBuffer));
char*. Casting the result to char* won't convet the string from ASCII to
unicode. See below
MessageBoxA(NULL, pBuffer, "", 0);there
Strange thing is my CString class is within the WTL namespace, is
more than one implementation of CString available?this
What would be the best object to use for string handling, I thought
class was okay but have read sources on the net that say std::string isIt's a matter of opinion. Personally I prefer using std::string because it's
better...
more standard compatiable
Preferably I'd like to just use CString and convert it nicely...Thanks
loads in advance!IIRC, CString has no function to convert Unicode characters to ASCII ones.
However you can use mbtowc() or MultiByteToWideChar() to do the job
BTW, you can use TCHAR instead of char and use your normal functions
(MessageBox instead of MessageBoxA) and avoid all the hassle...
--
Abdo Haji-Ali
Programmer
In|Framez
.
- Follow-Ups:
- Re: CString to const char*
- From: NickP
- Re: CString to const char*
- References:
- CString to const char*
- From: NickP
- CString to const char*
- Prev by Date: Re: CString to const char*
- Next by Date: Re: CString to const char*
- Previous by thread: Re: CString to const char*
- Next by thread: Re: CString to const char*
- Index(es):
Relevant Pages
|