Is there a way to make all character sequences UNICODE by default? For instance, now I have to say:
std::wstring wstr(L"rofl");
instead, I'd like to say
std::wstring wstr("rofl");
Thanks!
Visual C++ 8.0
Is there a way to make all character sequences UNICODE by default? For instance, now I have to say:
std::wstring wstr(L"rofl");
instead, I'd like to say
std::wstring wstr("rofl");
Thanks!
Visual C++ 8.0
No, there is no such thing. Many platforms intended for compiliation with either Unicode or ASCII (but not both) provide a macros to allow easy selection of the desired character type (often _
is used, e.g. _("text")
). You can use this if your issue is compiling for both options. Otherwise, it's only an additional character.
Also, bear in mind the exact encoding of wchar_t
may vary from platform to platform. Sometimes it is UTF-16, sometimes it is UTF-32. C++1x will add explicit encoding-specified strings u8"string"
u"string"
and U"string"
. (I could be wrong about the prefixes, but there will be such strings).
I was surprised by this: Doesn't wstring have a wstring(const char *) constructor??
As an aside, CString supports cross-width construction (eg: CString("text") will work for Unicode builds, and CString(L"text") for MBCS builds), but still does a conversion in both cases. That might accomplish what you want, at the cost of performance.
I'd suggest getting used to using _T("text"), as that's generally what you want.