cout a string gets the address instead of value [d

2019-03-06 23:42发布

This question already has an answer here:

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!

标签: c++ macros cout
1条回答
Ridiculous、
2楼-- · 2019-03-07 00:15

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;
查看更多
登录 后发表回答