1

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?

cadaniluk
  • 15,027
  • 2
  • 39
  • 67
Ben Marconi
  • 161
  • 1
  • 1
  • 7

1 Answers1

1

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];
Dinal24
  • 3,162
  • 2
  • 18
  • 32
  • Thanks! That's actually simpler lol but why will it let me make a string array in int main but not in a struct outside of int main?? – Ben Marconi Nov 08 '15 at 18:00
  • This may help solve your issue! http://stackoverflow.com/questions/6652165/default-values-for-arrays-members-of-struct – Dinal24 Nov 09 '15 at 17:11
  • @BenMarconi you can upvote and mark as the answer if you found it useful! ;) – Dinal24 Nov 09 '15 at 17:12