The right style for interacting with legacy TCHAR code

I am changing the code of another user who uses TCHAR extensively. Is it better to use only std :: wstring in my code? wstring should be equivalent to TString on widescreen platforms, so I don't see a problem. The rationale is that it is easier to use raw wstring than to support TCHAR ... for example, using boost: wformat.

Which style will be more understandable for the next maintainer? I spent several hours trying to understand the string details, it seems that just using wstring will cut half what you need to understand.

typedef std::basic_string<TCHAR> TString; //on winxp, TCHAR resolves to wchar_t
typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;

... The only difference is the dispenser.

In the unlikely event that your program lands on a Window 9x machine, there is still an API layer that can translate your UTF-16 strings to 8-bit characters. There is no point in using TCHAR to develop new code. source

+2
source share
2 answers

If you only plan on using Unicode platforms (wchar_t), you better use std :: wstring. If you want to support multibyte and Unicode assemblies, you will need to use TString, etc.

, basic_string char_traits allocator , , UNICODE ( _UNICODE, , ), TString wstring .

. API- , const wchar_t * std:: wstring (, Win32, COM ++) .

+2

TCHAR , , char wchar_t.

, , MSVC MBCS Unicode .

, API .

0

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


All Articles