C++ windows how to convert 'unsigned int' to 'TCHAR *'?

Gana picture Gana · May 7, 2013 · Viewed 11.6k times · Source

I am in new to C++ on windows. Can you please tell me how to convert unsigned int to TCHAR *?

Answer

bobobobo picture bobobobo · May 7, 2013

The usual way is to use swprintf to print wide characters into a wchar_t (which TCHAR is normally defined as).

To print numbers into a TCHAR, you should use _stprintf as @hvd mentions below (in a fit of rage). This way if UNICODE is defined you will use wide characters, and if UNICODE is not defined you will use ASCII characters.

int myInt = 400 ;
TCHAR buf[300] ; // where you put result
_stprintf( buf, TEXT( "Format string %d" ), myInt ) ;