我一直在使用messageBox()顯示String uptill。我怎樣才能使用這個函數顯示一個整數?我想是這樣的,但它沒有工作:在C中使用messageBox()函數顯示一個整數?
int message=1;
MessageBox(NULL,
(LPCSTR)message,
"Display",
MB_ICONINFORMATION);
我一直在使用messageBox()顯示String uptill。我怎樣才能使用這個函數顯示一個整數?我想是這樣的,但它沒有工作:在C中使用messageBox()函數顯示一個整數?
int message=1;
MessageBox(NULL,
(LPCSTR)message,
"Display",
MB_ICONINFORMATION);
您需要將int
放入一個字符串。在C語言中,你可以使用sprintf()
:
char buffer[32];
sprintf(buffer, "%d", message);
MessageBox(NULL, buffer, "Display", MB_ICONINFORMATION);
和C++中有幾個選項(參見Append an int to a std::string的建議),用於存儲在std::string
的int
然後用std::string::c_str()
在調用MessageBox()
。
是C還是C++? – NPE 2013-03-15 11:15:55
我正在使用C ... – Ayse 2013-03-15 11:41:44