将SHORT转换为TCHAR?

时间:2013-12-18 17:58:31

标签: c++ winapi short tchar

我正在编写一个Win32程序,我想将X pos和Y pos发送到屏幕,我想知道如何将SHORT转换为TCHAR。不要使用 atoi或itoa功能。

这是一个玩具程序,我想说明鼠标的位置,但我不知道如何将短片转换为TCHAR。

3 个答案:

答案 0 :(得分:1)

也许你想将unsigned int转换为字符串。如果将TCHAR定义为WCHAR,则可以使用std :: to_wstring:

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

然后将s.c_str()转换为TCHAR*

答案 1 :(得分:1)

你可以使用stringstream。

#include <sstream>

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

TextOut(GetDC(hWnd), 100, 100, reinterpret_cast<TCHAR *>(ss.str().c_str()), ss.str().size());

答案 2 :(得分:0)

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
相关问题