cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
input validation
input validation
Jan 30, 2011 at 3:40am UTC
sloper
(5)
Hello knowledgeable peoples,
char name[4]
cout<<"Enter Bob or Ted";
cin>>name;
How do I verify that input was Bob or Ted and not fred or 69&? Is it possible with char or do I have to use strings and if so how?
Thank you.
Jan 30, 2011 at 3:58am UTC
PanGalactic
(1658)
Avoid char arrays for stream input at all costs. Use only std::string.
Then you just need to check:
if
(
"Bob"
== name or
"Ted"
== name) { OK... }
else
{ Bad... }
Topic archived. No new replies allowed.