I have a (hopefully) simple question about getting some input from the user. I need to take input from the user and convert it to an integer.
Any ideas?
I have a (hopefully) simple question about getting some input from the user. I need to take input from the user and convert it to an integer.
Any ideas?
the atoi() function is the thing you are looking for if the input is in char form
-
and itoa() if you want to go the other way
Is that air you're breathing?
the >> operator will place user input directly into an int variable, assuming the input is appropriate length, and consists only of numerals. If you try to put inappropriate input into an int variable it may cause any of a number of things to happen, not the worst of which is crash your program. Therefore, one approach is to accept all input as a string, and then parse the string for erroneous input, and convert it to the desired type when adequately evaluated. (There are other ways to ensure data entry integrity, too, but that's a different story).
Excellent! Thank you all for your help, I'll put this to use immediately.