How to Read from stdin in Cpp

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.