How to Read from stdin in Cpp

Tue, Dec 1, 2015

Read in 1 minutes

Reading from stdin in C++ is surprisingly concise. Only 12 lines of code (including includes and empty lines).

We need the iostream header for access to std::cin and std::cout and we need the string header for - strings.

std::getLine reads from the stream (in our case, with std::cin, the stdin input stream) on a line by line basis, and writes the result into the line string object. This objects content is then written to std::cout (the stdout output stream) prefixed by the current line number.

See Also

How to Read from stdin in Haskell

Wed, Dec 2, 2015

Read more →

How to Read from stdin in Lisp

Wed, Nov 25, 2015

Read more →

How to Read from stdin in Java

Mon, Aug 31, 2015

Read more →

How to Read from stdin in Ruby

Fri, Aug 28, 2015

Read more →

How to Read from stdin in JavaScript

Thu, Aug 20, 2015

Read more →