Howdy, I have a few questions regarding the use of ctime within a class.
I followed the example on http://www.cplusplus.com/reference/clibrary/ctime/strftime/
When the program is like this, it works:
#include <ctime>
#include <iostream>
using namespace std;
int main(){
time_t current_seconds;
current_seconds = time(NULL); //Fills current_seconds with the number of seconds since January 1, 1970
struct tm * timeinfo;
char buffer [80];
time (¤t_seconds);
timeinfo = localtime (¤t_seconds);
strftime (buffer,80,"Event Date: %x",timeinfo); //Modifies timeinfo into a user readable format
puts(buffer); // Posts the string "buffer"
strftime (buffer,80,"Event Time: %X %Z",timeinfo);
puts(buffer);
return 0;
}
Question 1: Is it possible to place this in a class, such as class Event_Time:?
class Event_Time {
public:
time_t current_seconds;
current_seconds = time(NULL); //Fills current_seconds with the number of seconds since January 1, 1970
struct tm * timeinfo;
char buffer [80];
time (¤t_seconds);
timeinfo = localtime (¤t_seconds);
strftime (buffer,80,"Event Date: %x",timeinfo); //Modifies timeinfo into a user readable format
puts(buffer); // Posts the string "buffer"
strftime (buffer,80,"Event Time: %X %Z",timeinfo);
puts(buffer);
};
However, when I paste the code in VS2010, everything shows up red, even though I've included <ctime> and I'm placing it before main. The majority of the errors read: "this declaration has no storage class or type specifier"
Question 2: can I assign a variable to the value of timeinfo?
Meaning event_time = timeinfo;
I attempted to do:
tm event_time;
event_time = localtime(¤t_seconds);
but I get the warning/error "no operator matches these operands"