【Windows.net】如何用outtextxy函数输出int整型数

outtextxy函数是Graphics头文件中提供的输出字符串的函数,按照道理来说应该很易于使用,但是我写程序时发现了一些问题,在我程序中无法正确输出整型数,网上提供的方法x.str()等方法对我不管用,于是我采用了最原始的

int-->string-->char[ ]-->LPCTSTR转换。虽然复杂,但是肯定有效。

outtextxy函数定义为:

void outtextxy(int x, int y, LPCTSTR str); 

void outtextxy(int x, int y, TCHAR c);

转换的代码为:

//假设该整型数为num,num1和num2也是整型数
string temp = to_string(num);
char s[100];
int i;
for (i = 0; i<temp.length(); i++)
	s[i] = temp[i];
s[i] = '\0';
int n = MultiByteToWideChar(0, 0, s, -1, NULL, 0);
wchar_t *wide = new wchar_t[n];
MultiByteToWideChar(0, 0, s, -1, wide, n);
outtextxy(num1, num2, wide);

 

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值