-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,435
  • 7
  • 29
  • 45
sky
  • 522
  • 8
  • 13

1 Answers1

2

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
  • 555,201
  • 31
  • 458
  • 770
yzt
  • 8,873
  • 1
  • 35
  • 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