Display time with class member function

I am trying to make a member function of a class show the time. Can anyone tell me what I am doing wrong, please?

The Includes:
1
2
#include<iostream>
#include <time.h> 


The class declaration:
1
2
3
4
5
class easteregg
{
public:
    void time(void);
};


The function definition:
1
2
3
4
void easteregg::time(void)
{
    cout << "Current time is:  " << localtime() << "\n\n";
}


This one is giving me a gigantic headache. I can either take Tylenol or ask for help. And I am out of Tylenol. Thanks ahead of time. Pun intended.
localtime() returns struct tm *. You have to do more to get the desired output. You may use asctime() or you can use the struct directly.
You mean, like this?

1
2
3
4
void easteregg::time(void)
{
    cout << "Current time is:  " << localtime(struct tm *) << "\n\n";
}
No, like this

1
2
3
4
void easteregg::time(void)
{
    cout << "Current time is:  " << asctime(localtime()) << "\n\n";
}
Ohhh. Cool. Do I use time.h for that, still? And thanks for the help. :)
Do I use time.h for that, still?
Hm yes, that should work. Why do you ask? You can also use strftime() which provides more functionality
I put it in how you showed and it wouldn't work for me. I can't remember what the error was as I have been trying a ton of different things in order to make heads or tails from it. I am still totally confused about this. I did it before without any problems but I can't find that program anymore.
Topic archived. No new replies allowed.