显示的MessageBox℃的变量++ [英] Display a Variable in MessageBox c++

查看:201
本文介绍了显示的MessageBox℃的变量++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在MessageBox中C显示可变++?

How to display a Variable in MessageBox c++ ?

string name = "stackoverflow";

MessageBox(hWnd, "name is: <string name here?>", "Msg title", MB_OK | MB_ICONQUESTION);

我要显示它在下面的方式(#1):

I want to show it in the following way (#1):

"name is: stackoverflow"


和本?

int id = '3';

MessageBox(hWnd, "id is: <int id here?>", "Msg title", MB_OK | MB_ICONQUESTION);

和我想表明它通过以下方式(#2):

and I want to show it in the following way (#2):

id is: 3

如何用C做++?

推荐答案

创建一个临时缓冲区来您的字符串存储和使用的sprintf ,根据您的变量更改格式类型。对于你的第一个例子以下应该工作:

Create a temporary buffer to store your string in and use sprintf, change the formatting depending on your variable type. For your first example the following should work:

 char buff[100];
 string name = "stackoverflow";
 sprintf_s(buff, "name is:%s", name.c_str());
 cout << buff;

然后调用消息框的​​buff作为字符串参数

Then call message box with buff as the string argument

MessageBox(hWnd, buff, "Msg title", MB_OK | MB_ICONQUESTION);

有一个int更改为:

int d = 3;
sprintf_s(buff, "name is:%d",d);

这篇关于显示的MessageBox℃的变量++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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