int main()
{
int a;
time_t rawTime;
struct tm* localTime;
char buffer[1024];
while(true)
{
cout <<"\nThis is a timer program"<<endl;
cout<<"key in your input :"<<endl;
cin >> a;
time(&rawTime);
localTime = localtime(&rawTime);
strftime(buffer, 1024, "\nThe time is: %I:%M%p and %S seconds, and today is %A, %B %d, %Y.", localTime);
puts(buffer);
pause(1);
The timer cannot run after i put the cin >> a,is there anyway to separate the timer and the statement?For example i want the program to let me key in the value while the timer keeps running without interuption by keeps changing it's clock value.
reads the time only in that moment when u call the function. So in other words it reads the time from system clock when u use the function. If u want u can use that function again another time or use a loop witch is looking for a specified time.(something like pause() ).
I still cannot figure it out ,i tried several other ways but the timer and the cin object cannot occur simultineously.What i want for the program content is about a group of selection menu display first,then the timer appeared after the last part of the menu,cin statement prompt out to let me key in the selection.
I still cannot figure it out ,i tried several other ways but the timer and the cin object cannot occur simultineously.What i want for the program content is about a group of selection menu display first,then the timer appeared after the last part of the menu,cin statement prompt out to let me key in the selection.
You need to do some study on multi-threaded development. That will let you thread your timer off so it will continuously run while your other code is working. Unfortunately, Multi-threaded development is exponentially harder than normal coding.