Вопрос

I am coding a Win32 Program,and I want to text out the X pos and Y pos to the Screen, and I want to know how to convert SHORT to TCHAR. don't use the atoi or itoa function.

This is a toy program, and I want to text out the position of the mouse, but I donnot konw how to convert short to TCHAR.

Это было полезно?

Решение

Maybe you want to convert a unsigned int to a string. You can use std::to_wstring if TCHAR is defined as a WCHAR:

short x = 123;    
std::wstring s = std::to_wstring(x);

Then convert s.c_str() to a TCHAR*.

Другие советы

You could use stringstream.

#include <sstream>

std::stringstream ss("");
ss << nX << " " << nY;

TextOut(GetDC(hWnd), 100, 100, reinterpret_cast<TCHAR *>(ss.str().c_str()), ss.str().size());
SHORT myVal;
TCHAR buf[32]; // 32 is big enough to contain a 16-bit int as a string

_stprintf_s(buf,ARRAYSIZE(buf),"%hd",myVal);
// now buf contains the text as a TCHAR
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top