|
-
Jan 3rd, 2002, 02:33 AM
#1
Thread Starter
Hyperactive Member
How to validate cin input?
Now I am making transition from C to C++.
In the past using C, I validated by using getchar or gets, then I validated them.
For example, the input is supposed to be integer, I will check the string for any non-numeric char, if no, I will convert it to int.
Now I was writing a program using cout and getchar. It compiles alright and links alright but it hangs after cout and not getting any input from me. ????
I have changed all to cin as I am the only one who use the program so I can't enter any invalid input, given the fact the program is written by me too.
Given the scenario, the program's end user is not me, how do I verify?
Thanks.
-
Jan 3rd, 2002, 05:03 AM
#2
Addicted Member
To validate users input you can use cctype.h with its functions like isalpha(), isdigit(), etc.......
To convert from integer to double, I think you can just write double(entered numbers).
-
Jan 6th, 2002, 11:41 AM
#3
int i;
cin >> i;
You don't need to validate. i will be an integer no matter what (worst case: i will be 0).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|