© Will Briggs 2019
Will BriggsC++ for Lazy Programmershttps://doi.org/10.1007/978-1-4842-5187-4_5

5. Loops, Input, and char

Will Briggs
Lynchburg, VA, USA
In this chapter we’ll look at repeated actions, input, and things to do with the character type.

Keyboard input

Consider this code:
int ageInYears;
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.) ssin 1 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 ...

Get C++ for Lazy Programmers: Quick, Easy, and Fun C++ for Beginners now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.