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.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.