I think there are many problems with your code memeguy.
Do you realize that your code is missing a couple semicolons and you have
std::cout
while you have
endl
without the namespace???
void mainloop()
? I really cannot imagine what good does redirecting the
int main()
function will give...
Why are you going in a loop to increment a value 6 times, when you could just type in += 6?
And have you thought about the fact that you need to add a minute for every 60 seconds of the clock, not just 1 single minute??? And even if you set it up for it (you need to do the loops starting with hours, then minutes, then seconds), it would still be waste of time considering that the standard library can do it very efficiently...
This is how it is supposed to look like, but I think the chrono style looks much better if you want display just 1 unit of time, like seconds, and it has better accuracy because it can display floats.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <ctime>
#include <thread>
#include <chrono>
int main(void)
{
std::time_t result;
result = std::time(NULL);
std::this_thread::sleep_for (std::chrono::seconds(1));
//multiplied by 6 for request.
result = (std::time(NULL) - result)*6;
char mbstr[100];
//%T is meerly a convenience format of %H:%M:%S"
if (std::strftime(mbstr, sizeof(mbstr), "%T", std::localtime(&result))) {
std::cout << mbstr << '\n';
}
//I cannot get this to work with cpp.sh for the life of me, but works on cppreferences's compiler.
//std::cout << std::put_time(std::localtime(&result), "%T") << '\n';
return(0);
}
| |
You can also use chrono's system_clock and call
std::chrono::system_clock::to_time_t
to use chrono and have formatting in the same time. And in c++20 there will be a std::chrono::format, which does what my example does.