I am new to programming in C++ and I am trying to convert an Integer to a string. would the function c_str work?
I am new to programming in C++ and I am trying to convert an Integer to a string. would the function c_str work?
No.
Click Here There should be a couple links that will answer your question.
but .c_str() is a string fxn that converts a std::string to a c string.
Code:#pragma hdrstop #include <condefs.h> #include <stdlib.h> #include <stdio.h> int main(void) { int number = 12345; char string[25]; itoa(number, string, 10); printf("integer = %d string = %s\n", number, string); getchar(); return 0; }
Hi I'm using CBuilder4 and found this code in the help!
Hope it helps,
Colin
>>I'm using CBuilder4 and found this code in the help!
That's all C code, and non-standard at that.
Like alpha said, the answer is in the FAQ.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
He's New, I'm New.....
I've asked for and received great help in the past. I read this site everyday and if there is something I can do to help someone I will. I am now getting a bit sick of the replys I get for the Super Dooper Moderators after I offer a suggestion. As I said I'm New to this and I'm only trying to help where I can.
Thanks for the boost of confidence Hammer.
Signing off, won't be back...
Colin.
Colin:
Calm down!
What Hammer said is correct. The questioner is asking for C++ help, giving him printf() is likely to confuse, as he may not have covered legacy code, as you yourself have pointed out, he is new.
You did, also, give a compiler specific solution, which again might confuse and discourage a newcomer.
>>> getting a bit sick of the replys I get
I don't know which other threads you are referring too, but Hammers reply to this question is entirely correct, the answer is explained in the FAQ, and the code sample you have provided is not a general solution.
>>> Signing off, won't be back...
In which case I guess typing this was a waste of time...
Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.
Colin you are not new to this. You have been trying to program for 4 years now.
Come on. Stop complaining.
Thank you for the valuable information. I was trying to figure it out and I did not know about the FAQ section. Thanks for reminding me.