I need quick help in converting a month number input by the user to a string:

cin>> 1 so when i do a cout it should output: " january" ;

cin>>2 so output: february...

Remark im trying to do the reverse of this: int i = Convert::ToInt32(myString);

Basically is it possible for me to call the array below in &operator to return me a string of the month that i will input in option 1 And how I am a bit confused... Sad Thank you

// overloaded output operator

ostream &operator<<( ostream &output, const Date &d )


static char *monthName[ 13 ] = { "", "January", "February", "March", "April", "May", "June", "July", "August","September", "October",

"November", "December" };

output << monthName[ d.month ] << ' ' << << ", " << d.year;

return output; // enables cascading

} // end function operator

void option1(Date mdate [] , int sz, int& countdate)


char bufferMonth[13];

int choice;

Date tmpDate;

int index = 0;

int month;

int tmpMonth, tmpDay, tmpYear;

bool isOK = false;

while ( !isOK && ( countdate < sz ))


cout << endl;

cout << "Enter the month (1 to 12): "; // input the month using getline

// cin.ignore();

// cin.getline(bufferMonth,10);

// StringToInt(bufferMonth, tmpMonth);

// tmpMonth = string (bufferMonth);


/* Conversion from Int to String goes here */





Re: Visual C++ General Integer to String


I hope the next sample can help you:

const char * ConvertIntegerToMonthName(int m)


static const char * monthName[] = { "",

"January", "February", "March", "April",

"May", "June", "July", "August",

"September", "October", "November", "December" };

return monthName[m]; // TODO: check for errors


Sample usage:

int month;

cin >> month;

const char * const monthName = ConvertIntegerToMonthName(month);


std:: string const monthName = ConvertIntegerToMonthName(month);


char monthName[20];

strcpy(monthName, ConvertIntegerToMonthName(month));

Re: Visual C++ General Integer to String

Marius Bancila

In ConvertIntegerToMonthName you have to make sure than m is between 0 and 11.

Re: Visual C++ General Integer to String


omg thank you both i arranged what you guys gave me to fit my code!!!

It works fine now... thanks for the quick answer Viorel and Marius it helped me a lot.. i really appreciate.