© Will Briggs 2021
W. BriggsC++20 for Lazy Programmershttps://doi.org/10.1007/978-1-4842-6306-8_5

5. Loops, Input, and char

Will Briggs1  
(1)
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 press 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++20 for Lazy Programmers: Quick, Easy, and Fun C++ for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.