I am having to write a program that has a user-defined class. In this program I need to convert an INT to a STRING. For example, if the program reads in the date "7/17/2009" it will need to be converted to "July 17, 2009", where all it does is take the month's number value and change it to the string equivalant.
Can somebody help me with the INT to STRING conversion? I can't quite grasp it.
Here is what I have thus far for the implementation of my class:
I'm not far enough along in my programming class to use templates. I am still a few chapters away from that. Thanks for the help but I will need something a little more simplistic or slightly different.
I can`t see anything basically wrong with your code, Why dont you write a main() driver for it and determine where the faults lie? If i had one criticism it would be that you have tried to encompass every contingency in your code (e.g leap year determination ) instead of concentrating on the conversion first. There is no indication of how the input is to be provided.
If it were cin>>m>>d>>y ; a simple enum statement could suffice.
e.g enum month{Jan=1,Feb,Mar, etc}.....but in any case the switch construct would print out the month and the remaining 2 cin inputs repeated with cout<< plus punctuation would complete the output.
hth`s
rgds
For the same reason that it matters to use int main() instead of void main(). Writing code that compiles only on select compilers is defeating the purpose of having a portable language.
How exactly is this
1 2 3 4 5 6 7 8 9 10 11 12 13
//no std:: and no sign of using namespace
string IntToString(int intValue) {
char *myBuff;
string strRetVal;
//Dynamic allocation of constant size. Brilliant.
myBuff = newchar[100];
//'\0': when 0 is just not good enough.
memset(myBuff,'\0',100);
itoa(intValue,myBuff,10);
strRetVal = myBuff;
delete[] myBuff;
return(strRetVal);
}