C++ std::istream::get() Function

Definition
In C++, get() reads exactly one character from an input stream. Unlike cin >> c, it does not skip spaces, tabs, or new lines. Every character is returned just as it was typed.
It has three common forms: get() returns the character, get(c) stores it in a char, and get(buffer, n) reads a short piece of text into a character array. Include <iostream> to use it.
This is a member function of std::istream. You call it with a dot on a stream object, for example std::cin, std::cout, a file stream, or a std::stringstream. A stream is simply C++'s way to read or write data one piece after another.
Syntax
Call get on an input stream. Choose the form that matches what you need.
C++
int ch = in.get(); // returns the character, or EOF
in.get(c); // stores it in c, returns the stream
in.get(buffer, 20); // reads up to 19 chars and adds '\0' | Call | What it does |
|---|---|
in.get() | Returns the next character as an int. At the end of input it returns EOF. |
in.get(c) | Stores the next character in c. The stream is returned, so it works in a while loop. |
in.get(buf, n) | Reads up to n - 1 characters, stops before the new line, and adds a |