Ben Marconi
Ben Marconi

Reputation: 171

looking for another time structure with member objects other than tm

the member tm_mon, in struct tm is stored as an integer. I'm looking for another time stuct that stores the actual name of the month. I can get the user-friendly format with

ctime();

but how can I selectively output just the month?

Upvotes: 1

Views: 41

Answers (1)

Dinal24
Dinal24

Reputation: 3192

Have an array like,

string Months[] = {"January", "February", ... };

Then when you want to print use,

time_t t = time(0);   // get time now
struct tm * now = localtime( & t );
cout << Months[now-> tm_mon];

Upvotes: 1

Related Questions