Input Handling
-
Using getline()
- getline() is a function that allows you to read input including
whitespace characters. See str.cpp
for an example on how to use getline()
Input
manipulators
- The noskipws manipuilator is another way to read whitespace
sharacters. An on-line example from C++ Reference on how to use
it appears here.
-
Input Techniques
- Validating Input: You can't always be sure the user of
your program is going to give you the answer you're looking for.
One way to protect your program from bad user data is to validate
your input and ask for it again of you get the wrong data. See validate.cpp for an example of
this.
- Parsing Input: Parsing input means to break the input
into its constituent pieces. For example, if were were to ask the
user for their full name, we might then want our program to break the
full name into first name, middle initial (or middle name) and last
name. Breaking up the name into its parts is called parsing the
name. See parse.cpp as one
example on how we might do this.