0

Should I be using std::wstring or std::string and wchar_t or char?

All this unicode stuff is confusing me. I want my application to work on both windows and linux without too many problems and changes but I'm considering unicode vs. ansi.

Any ideas? I ask because I see many applications still using std::string and chars insead of the unicode equivalents.

3
Contributors
2
Replies
19
Views
4 Years
Discussion Span
Last Post by vijayan121
0

It depends on what you need. If you need unicode characters, then use the wide varients of the char type and it's related wide std::string type. The char type will work on Windows and Linux, but if you try to use unicode, it will fail on Windows and Linux.

1

Depending on the character set that is being used internally, either char / std::string or wchar_t / std::wstring as appropriate.

To communicate with the outside world (for instance performing file i/o or communicating over the network), ideally use utf8 encoded chars and std::string or char16_t and std::std::u16string (which are utf16 encoded).

See: http://en.cppreference.com/w/cpp/header/codecvt
http://en.cppreference.com/w/cpp/locale/wbuffer_convert
http://en.cppreference.com/w/cpp/locale/wstring_convert

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.