I've spent countless hours googling how to do this. I've read many solutions and still confused. Most of the solutions deal with an automatic input into the variable string, for example string test = "123". I want a prompt to appear asking the user to input a string or char and it will convert it to a integer for example a phone number. I tried using atoi but it returns 0. I tried stingstream convert but get an error. This is what I got so far: It converts it into ASCII but they give a double digit for each letter. Is there a easier way?? P.S. the cin.get function is suppose to draw only 7 char/string out of the user input and convert it into a phone number
The functions ToString() and FromString() at http://ideone.com/WffuF work just fine as you can see from the demo, so long the entered string correctly represents a number (or in general, correctly represents data from the specified data type).
char letters[9999];
int length = strlen(letters);
int num2[length];
is incorrect. First of all length can have any value because array letters was not initialzed.
Secondly C++ does not allow ro define varable length array. So the definition of array num2 is incorrect.