显示一个整数使用的MessageBox()的C函数? [英] Display an Integer using messageBox() Function in C?

查看:295
本文介绍了显示一个整数使用的MessageBox()的C函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经显示字符串uptill现在用的MessageBox()。如何显示使用该功能的整数?我想这样的事情,但它没有工作:

 整型消息= 1;
的MessageBox(NULL,
           (LPCSTR)消息,
           显示,
            MB_ICONINFORMATION);


解决方案

您需要把 INT 成一个字符串。在C语言中,你可以使用 的sprintf()

 字符缓冲区[32];
sprintf的(缓冲,%D,消息);
的MessageBox(NULL,缓冲,显示,MB_ICONINFORMATION);

和C ++中有几个选项(参见<一个href=\"http://stackoverflow.com/questions/10516196/append-an-int-to-a-stdstring/10516313#10516313\">Append用于存储一个int到一个std ::对于建议字符串)的 INT 的std ::字符串然后用的std ::字符串:: c_str()在调用的MessageBox()

I had been displaying String uptill now using messageBox(). How can I display an integer using this function? I tried something like this but it didn't work:

int message=1;
MessageBox(NULL,
           (LPCSTR)message,
           "Display",
            MB_ICONINFORMATION);    

解决方案

You need to place the int into a string. In C, you can use sprintf():

char buffer[32];
sprintf(buffer, "%d", message); 
MessageBox(NULL, buffer, "Display", MB_ICONINFORMATION);

and in C++ there are several options (see Append an int to a std::string for suggestions) for storing an int in a std::string then use std::string::c_str() in the call to MessageBox().

这篇关于显示一个整数使用的MessageBox()的C函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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