好吧,使用 CMD (Iostream.h),您可以使用 << >> 来传递数据。就像如果我想显示文本和带有文本的变量,我会说。
cout << "You have " << numberofApples << " of apples.";
如何在我的消息框/SetWindowText 等中显示文本和变量。我确实在谷歌上搜索过,但我不完全知道你怎么调用它,所以我找不到任何明确的答案。
谢谢!
最佳答案
有一个 std::stringstream
类允许您创建类似于 std::cout
的流,但它将格式化输出放入字符串中,因此您可以用它做事(在消息框中显示,通过网络发送等)
例如,将您的代码与消息框一起使用看起来像
#include <sstream>
#include <windows.h>
...
std::stringstream box_message;
box_message << "You have " << numberofApples << " of apples.";
MessageBoxA(0, box_message.str().c_str(), "My Message Box", MB_OK);
还有 std::wstringstream
可以与 Unicode (UCS-2) 一起使用来显示东方语言(并使用 MessageBoxW
)
关于c++ - 如何在 Messagebox 中显示变量+文本? Winapi32 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33088635/