使用 wsprintf 将 int 转换为 LPCWSTR [英] Convert int to LPCWSTR by using wsprintf

查看:26
本文介绍了使用 wsprintf 将 int 转换为 LPCWSTR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下代码:

int a = 16;
wchar_t *buffer = {0};
wsprintf(buffer,L"%d", a);

MessageBox(NULL, buffer, buffer, MB_OK);

我想将 int 转换为 LPCWSTR 以放置 MessageBox.我真的是使用 wsprintf 的新手.任何人都可以用这个功能帮我解释清楚???(拜托,我也读过 MSDN 但还是不清楚)

I want to covert int to LPCWSTR in order to put MessageBox. I really newbie in using wsprintf. Any one can help me explain clearly for me using this function??? (Please, I also read MSDN but still dont't clear)

我的意思是,我想在 MessageBox 中打印16"

I mean, I want to print "16" in MessageBox

推荐答案

您将 buffer 初始化为 nullptr.只需创建一个 wchar_t 数组,为您分配足够的空间,您就可以摆脱困境:

You initialize your buffer to nullptr. Just create an array of wchar_ts that allocates enough space for you and you're off the hook:

int a = 16;
wchar_t buffer[256];
wsprintfW(buffer, L"%d", a);
MessageBoxW(nullptr, buffer, buffer, MB_OK);

这篇关于使用 wsprintf 将 int 转换为 LPCWSTR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆