#include <windows.h>
#include <tchar.h>
#include <limits>
int WINAPI _tWinMain ( HINSTANCE,
HINSTANCE,
_TCHAR *,
int )
{
// 整数の場合は、桁数に、マイナス"-"記号分と、終端のNULLの分を追加
_TCHAR *pszInt = new _TCHAR[ std::numeric_limits < int >::digits10 + 2 ];
wsprintf ( pszInt, _TEXT ( "%d" ), -123456 );
MessageBox ( NULL,
pszInt,
_TEXT ( "test" ),
MB_OK );
delete[] pszInt;
// unsignedであれば、桁数に、終端のNULLの分のみ追加
_TCHAR *pszUINT = new _TCHAR[ std::numeric_limits < unsigned int >::digits10 + 1 ];
wsprintf ( pszUINT, _TEXT ( "%d" ), 123456 );
MessageBox ( NULL,
pszInt,
_TEXT ( "test" ),
MB_OK );
delete[] pszUINT;
return 0;
}
|