问题
There is a macro defined as below:
#ifdef UNICODE
typedef wchar_t TCHAR;
#define TEXT(quote) L##quote
#else
typedef char TCHAR;
#define TEXT(quote) quote
#endif
When I try to print a message using std::cout as below:
TCHAR* test = TEXT("test");
cout << test;
What I get the address such as 00D82110 instead of the value "test".
Can anybody give any suggestion how can I print the value here? Thanks a lot!
回答1:
You need to use wcout
instead of cout
for wide characters. Do this:
#ifdef UNICODE
typedef wchar_t TCHAR;
#define TEXT(quote) L##quote
#define COUT wcout
#else
typedef char TCHAR;
#define TEXT(quote) quote
#define COUT cout
#endif
and then:
TCHAR* test = TEXT("test");
COUT << test;
来源:https://stackoverflow.com/questions/24007507/cout-a-string-gets-the-address-instead-of-value