© Will Briggs 2019Will BriggsC++ for Lazy Programmershttps://doi.org/10.1007/978-1-4842-5187-4_5
5. Loops, Input, and char
In this chapter we’ll look at repeated actions, input, and things to do with the character type.
Consider this code:
sout << "How old are you? "; ssin >> ageInYears;
This prints the query about age, then waits for keyboard input. If the user enters a number, that number is stored in ageInYears
. (Anything else is likely to give ageInYears
a 0 value.)
waits for you to hit Enter before it processes input, so backspacing is allowed.
ssin uses the same font and cursor as sout; they are both part of SSDL.
You may note how the << arrows go: with sout, they go from ...