When do we prefer wide character strings?

I am upgrading a large, outdated MFC code base that contains a true mixture of string types:

  • Cstring
  • std :: string
  • stand :: wstring
  • char *
  • wchar_t *
  • _bstr_t

I would like to standardize one type of string inside and convert to other types only when it is absolutely necessary for a third-party API (i.e., COM or MFC functions). The issue that we are discussing with colleagues; What type of string should we standardize?

I would prefer one of the standard C ++ strings: std :: string or std :: wstring. I personally tend to std :: string, because we don’t need wide characters - this is an internal code base without a client-oriented user interface (i.e. multi-language support is not required). The "Plain" strings allow us to use simple, unvarnished string literals ("Hello world" versus L "Hello world" or _T ("Hello world")).

Is there an official position for the developer community? When you come across several types of strings, what is usually used as the standard "internal" storage format?

+4
source share
2 answers

Windows, std:: wstring ( ) wchar_t *, .

. Microsoft :

Windows Unicode , , . - , . Windows Unicode UTF-16, 16- . UTF-16 , 8- ANSI. Visual ++ wchar_t

:

Microsoft Unicode Windows, API, ANSI , Unicode. [...] , ANSI version Unicode.

:

Unicode. Unicode. ANSI, . ANSI , ANSI Unicode . [...] API Windows Unicode, ANSI.

+6

.

Windows std::wstring :

  • (, ..)
  • (Windows -ASCII- ( " " ), ANSI API)
  • COM (BSTR )
  • ( , ..)

ASCII UTF-8- . , .

, , API, / .. . .

"UTF-8 " - . 0 Windows API, UTF-8. API std::experimental::filesystem std::wstring Windows std::string POSIX.

+1

Source: https://habr.com/ru/post/1684831/


All Articles