Re: unicode macro
On 1 Nov., 16:29, tim todd <timza1...@yahoo.com> wrote:
Can I avoid doing this:
#ifdef UNICODE
std::wostringstream s;
#else
std::ostringstream s;
#endif
I have some string formatting code that I'd like to be both unicode
and not for use in different compiled modules. Is the #ifdef
necessary? How to avoid using it?
Thanks
Todd.
I would not use the preprocessor at this point, because
that would lead to much more preprocessor usages, if you
extend this kind of discrimination. I would introduce
only *one* such preprocessor decision to define a name
for the character type like this:
#ifdef UNICODE
typedef wchar_t TChar;
#else
typedef char TChar;
#endif
than use normal typedef's to define depending names.
Either use
std::basic_ostringstream<TChar> s;
directly or introduce a parallel series of typedef's
to replicate the std for TChar:
typedef std::basic_stringbuf<TChar> tstringbuf;
typedef std::basic_istringstream<TChar> tistringstream;
typedef std::basic_ostringstream<TChar> tostringstream;
typedef std::basic_stringstream<TChar> tstringstream;
....
and use these:
tostringstream s;
(In a windows environment you can use the system-specific
header tchar.h with it's own typedef TCHAR, but I prefer
above approach which is more portable anyway).
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]