How to read an integer from stdin

Here's a previous thread on the same topic, with discussion of the tradeoffs involved:

2 Likes