在MessageBox c ++中显示变量

问题描述 投票:7回答:4

如何在MessageBox c ++中显示变量?

string name = "stackoverflow";

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

我想以以下方式显示它(#1):

"name is: stackoverflow"

和这个?

int id = '3';

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

而且我想以以下方式显示它(#2):

id is: 3

如何使用c ++进行此操作?

c++ c windows messagebox
4个回答
8
投票

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


2
投票

这可以通过宏完成


0
投票

回答您的问题:


0
投票

这是唯一为我工作的人:

© www.soinside.com 2019 - 2024. All rights reserved.