Please help me to understand the algorithm from this source code.

int time(){
  time_t rawtime;
  struct tm * timeinfo;

  time (&rawtime);
  timeinfo = localtime (&rawtime);
  cout<<"Current time: "<<asctime(timeinfo);
}

Recommended Answers

All 3 Replies

What is rawtime?
time_t is type of rawtime,but why when I change 'rawtime' to another variable, the code doesn't work

I think the idea is to show the current time, but for this class should use a TIME function of the C + + library. Not sure why the class is using a pointer instead. It makes no sense to me.

localtime() returns a pointer to a tm structure. Then asctime() is called to convert the structure into something human readable, although you could do this yourself if you wanted to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.