What’s the usual/accepted way to achieve Unicode and ANSI support in Win32 programs with C++ string and stringstream classes? Is it best to write two versions of your code: one for ANSI and another for Unicode, or use some funky #ifdef’s and typedefs.
I was thinking for the latter, I could do something like this:
#include <string>
#include <sstream>
namespace lpr {
#if defined(UNICODE)
typedef std::wstring xstring;
typedef std::wstringstream xstringstream;
#else
typedef std::string xstring;
typedef std::stringstream xstringstream;
#endif // UNICODE
} Which might make the code seem odd, with things like ‘lpr::xstring’ all over the place, but it does seem to work well for supporting both ANSI and Unicode compilations.
Any suggestions?