1
votes

According to MSDN:

https://msdn.microsoft.com/en-us/library/windows/desktop/ff381407%28v=vs.85%29.aspx

You can write TCHAR for char or wchar_t depend on compiler MACRO UNICODE

Is there a similar symbol for std::string and std::wstring?

Thanks!

(My VC++ version is 2013)

3
The TCHAR and UNICODE macros are part of the Windows API, which is distinct from the C++ runtime library APIs. That's why there isn't already one. Visual C++ does provide some TCHAR-like functionality in the C runtime library, but that triggers off _UNICODE (note the leading underscore).Adrian McCarthy

3 Answers

4
votes

You could define it yourself:

typedef basic_string<TCHAR, char_traits<TCHAR>, allocator<TCHAR> >  tstring;
1
votes

I did not find one. I wrote one myself in my code like this -

#ifdef UNICODE
  #define tstring std::wstring
#else
  #define tstring std::string
#endif
0
votes

You can also tweak a bit by adding the namespace in your stdafx.h

namespace std {
    typedef basic_string<TCHAR, char_traits<TCHAR>, allocator<TCHAR> >  tstring;
}