Is there an string equivalent to LPTSTR? I know of string and wstring. Is there a tstring?
+8
A:
You could define one:
typedef std::basic_string<TCHAR> mystring;
...
mystring test = _T("Hello World!");
AraK
2009-12-01 06:53:28
Would you need to make new traits too?
GMan
2009-12-01 06:59:47
AFAIK `TCHAR` is either `char` or `wchar_t`. The standard provides a specialization for both types.
AraK
2009-12-01 07:02:36
GMan: tstring becomes an alias for either string or wstring (they are typedefs of basic\_string<char> and basic\_string<wchar\_t>, respectively).
Roger Pate
2009-12-01 07:24:50
Indeed, I was thinking completely wrong for a bit. This solution seems rather clean, then. (Just rename it `tstring` and throw it in a namespace :P)
GMan
2009-12-01 07:26:25
Hah, oops, I actually read the answer as 'tstring' instead of 'mystring', since that is the common name.
Roger Pate
2009-12-01 07:31:47
+1 elegant way to do it.
Jason D
2009-12-05 17:27:42
+1
A:
Another option (doesn't require windows.h
):
#if defined(_UNICODE) || defined(UNICODE)
typedef std::wstring ustring_t;
typedef wchar_t uchar_t;
#else
typedef std::string ustring_t;
typedef char uchar_t;
#endif
Usage:
ustring_t mystr = TEXT("hello world");
Kirill V. Lyadvinsky
2009-12-01 07:14:00
@Downvoter: Care to comment? Which bit do you disagree with?
Kirill V. Lyadvinsky
2009-12-01 07:36:30
Not the downvoter, but without `<windows.h>` you don't have the `TEXT()` macro either.
MSalters
2009-12-01 09:24:14
@MSalters, Only "usage" part requires TEXT macro. That's just an example.
Kirill V. Lyadvinsky
2009-12-01 11:08:06