I am trying to create a timestamp and at the moment I am trying to output it to the screen.
The function which I am attempting to use to do this is localtime_s.
However I cannot get it to work and I cannot find any working examples of how to use this.
I am encountering the following errors:
- Error 1 error C2660: 'localtime_s' : function does not take 1 arguments
- a value of type "errno_t" cannot be assigned to an entity of type "tm *"
- argument of type "time_t *" is incompatible with parameter of type "tm *"
too few arguments in function call
time_t rawtime; struct tm * timeinfo; time(&rawtime); timeinfo = localtime_s(&rawtime); asctime(timeinfo); cout << "Current local time and date: " << timeinfo << endl;
Can anyone please advise?
Edit
Using the answer to cover the cout problem, visual studio won't let me run asctime. So instead I tried using asctime_s which then displays "no instance of overloaded function "asctime_s" matches the argument list, argument types are : (tm *, time_t *)"
However using a pointer to timeinfo and rawtime causes further errors.
The code is now:
time_t rawtime;
tm timeinfo;
errno_t result = localtime_s(&timeinfo, &rawtime);
cout << "Current local time and date: " << asctime_s(&timeinfo, &rawtime) << endl;
Kind Regards