Re: Convert CString to LONG.
Control,
Giovanni is correct that you shouldn't mix metaphors. Many people say,
these days, that you should never use "char", but so long as you don't need
to do anything besides English it is still acceptable. What you don't want
to do is mix your types so having TCHAR then using strtol() could get you
into trouble. I prefer to always use the 't' version, and like David I
would not reassign the original value. I've seen a lot of people do this
sort of thing with std::string, for example,
#include <string>
namespace std {
#if defined _UNICODE || defined UNICODE
typedef wstring tstring;
#else
typedef string tstring;
#endif
}
So doing what David said and defining tcin and tcout the same would be a
better approach something like:
The whole mess with Unicode makes C++ way more difficult to use than any
other language. That's why I typically just use all the "T" macros:
TCHAR, _T(), etc.
I think they should have the tin tout stuff built in to be consistent, but
it doen't look like it is...
Tom
"Control Freq" <nick@nhthomas.freeserve.co.uk> wrote in message
news:457fee87-ed18-46bd-b7e5-f39046d3eb93@k37g2000hsf.googlegroups.com...
Thanks for the lengthy reply. I appreciate now why this is so
confusing. History has a lot to answer for!
So, for my code, is it acceptable to have:
#ifdef _UNICODE
#define cout wcout
#define cerr wcerr
#endif
at the top of some source file, or stdafx.h.
I understand the use of _T("XYZ") and I now know that I can't use
LPCSTR. And, if I use CString then my code can now compile with or
without _UNICODE, but if I need to cin, cout, cerr etc then my code
still needs some work.
Is there a Microsoft unicode-aware version of cin, cout and cerr?
Thanks in advance.