The last few posts came up quick.. sometimes it's easy to overlook a new post
The last few posts came up quick.. sometimes it's easy to overlook a new post
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
A lot of wasted time can be saved by clearly stating what you want to do when you first post. Up until this point you never stated that you wanted to return an integer.Originally Posted by stickman
Honestly I'm not sure you know what you want because you said Jawib's post is exactly what you wanted by that returns a string that contains the character representation of a number and not the number itself.
Please in the future think about what it is exactly that you wish to accomplish before you start a new thread and then clearly communicate that in the orginal post.
I'm sorry for the misunderstanding. Jawib's post converts int a to string a and when you return string a it returns an integer and yes I have tried it several times.Originally Posted by Thantos
The function in Jawib's post returns a string not an integer. Just look at the name: IntToString or look at the return type: string
What does that tell you?
Last edited by Thantos; 08-29-2004 at 12:13 PM.
If the numbers are only going to be unsigned single digits (0 to 9), there's a much simpler answer:
If they are not, this method will bring much WeirdStuff™.Code:blah += '0' + a;
But when the string is outputted, it outputs the int. Look at the FAQ page he posted. It says:Originally Posted by Thantos
/*
* Program output:
The int value is 5 and the string value is 5
Paused, press Enter.
*
*/
"and the string value is 5" and I believe that 5 is an integer so when the string is outputted it outputs "5" and not the symbol for 5.
Whenever you do output its as characters not as numbers. Say you have an int who's value is 12345. It prints the character 1, the character 2, the character 3, the character 4, and the character 5. cout has overloaded << operators which convert from whatever format into the individual characters that make that value.
using Jawib's main function in his post:
blah gets the return from IntToString(). blah is a string. If it was an int you should be able to doCode:int main() { std::string blah("Your number is: "); int num=1; blah+=IntToString(num); }and have it work correctly.Code:blah += 5;
You can not rely sololy on cout to tell you what the type of a variable is.