Display current system time in msgbox
-
04-12-2019 - |
Pregunta
I got error when I compile the following code, the error tells me that I have to convert unsigned short to char, i dont know how to perform this conversion. I'm using vc6 MFC. This is the code I used.
SYSTEMTIME st;
GetSystemTime(&st);
unsigned short time = st.wHour;
MessageBoxA(TEXT(time),"system time",MB_OK);
Solución
You could use a std::ostringstream
:
#include <sstream>
...
std::ostringstream time;
time << st.wHour;
MessageBoxA(time.str().c_str(),"system time",MB_OK);
Otros consejos
The variable time
is an integer, while MessageBoxA
wants a string. You have to convert the integer to a string, which is not done by the TEXT
macro. I suggest you read up more on either std::stringstream
or possibly sprintf
.
or ...
char str[20];
sprintf(str,"%d",st.wHour);
MessageBoxA(str,"system time",MB_OK);
Rodd Taylor
Saudi Arabia
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow