How can I record a time in the variable? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I record a time in the variable?

Hello everyone! I was reading about the ctime library and went to write a code, which must to output the time (number of hours, have passed since the 1 January 1970 Year). But when I initialize a variable, and assign to her the time, it’s error when i output the variable using cout. The type of variable is time_t, but i was using and int, and time_t. Help me please! 😢

28th Jun 2019, 3:34 PM
Igor The Golden Fish
Igor The Golden Fish - avatar
1 Answer
+ 2
#include <iostream> #include <ctime> int main() { std::time_t t; // Decalre a variable with type time_t std::time(&t); // use time() function to assign the current time to the variable std::cout << t << std::endl; return 0; } time() return the number of seconds since 00:00 hours, Jan 1, 1970 UTC.
28th Jun 2019, 3:47 PM
Mina Yossry
Mina Yossry - avatar