When to choose between using a wide string or not?

4

When using wide ( std::wstring ) or a normal string ( std::string )?

    
asked by anonymous 31.12.2017 / 11:30

1 answer

2

A difficult question to answer.

There is a tendency to use string on Linux and other platforms that use encryption that you have guaranteed 1 byte per character or that the characters are constructed by a set of bytes with quantity defined by the set itself where the most used example is UTF-8.

In Windows we usually use wstring that use characters that are guaranteed to be more than 1 byte. He is wide. UTF-16 or UTF-32 are the most commonly used.

Even on these platforms it is often best to use string . If the direct interaction with the operating system is small, it can compensate, even if it may require a conversion, the overall gain is greater. But it's pretty hard to hit the point.

We often use some library that abstracts this. It is not always the ideal.

Here is a controversy not so related to C ++. I try to use, where possible, encodings, with guaranteed size, primarily ASCII / Latin1 or something like that (almost always with you), if you do not go from UCS2 (it's almost UTF-16) and finally the UCS-4 / UTF-32 (I have never used it, but today it has application that may be necessary for one more mistake that the entity that defines these standards has committed). I only use UTF-8 and UTF-16 when I need to "talk" to external resources the application and that I have no control about its use.

See What are the main differences between Unicode, UTF, ASCII, ANSI? .

    
31.12.2017 / 12:41