-1

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!

Rakib
  • 7,215
  • 6
  • 27
  • 44
sky
  • 462
  • 5
  • 13

1 Answers1

3

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;
Remy Lebeau
  • 505,946
  • 29
  • 409
  • 696
yzt
  • 8,432
  • 1
  • 34
  • 44
  • Not "probably", but "definately". `cout` does not support `wchar_t` data, and `wcout` does not support `char` data. Passing a `wchar_t*` to `cout` and a `char*` to `wcout` both end up calling the `void*` streaming operator, which is why a memory address is being printed out instead of text. – Remy Lebeau Jun 03 '14 at 05:17
  • @RemyLebeau: I know. I was leaving room for suggestion of other methods (UTF8-format strings and such!) :D – yzt Jun 03 '14 at 05:20