| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Global objects | ||||
| Member functions | ||||
(C++11) | ||||
| Formatted input | ||||
| Unformatted input | ||||
basic_istream::get | ||||
| Positioning | ||||
| Miscellaneous | ||||
(C++11) | ||||
| Member classes | ||||
| Non-member functions | ||||
int_type get(); | (1) | |
basic_istream& get( char_type& ch); | (2) | |
basic_istream& get( char_type* s,std::streamsize count); | (3) | |
basic_istream& get( char_type* s,std::streamsize count, char_type delim); | (4) | |
basic_istream& get( basic_streambuf& strbuf); | (5) | |
basic_istream& get( basic_streambuf& strbuf, char_type delim); | (6) | |
Extracts character or characters from stream.
All versions behave asUnformattedInputFunctions. After constructing and checking the sentry object, these functions perform the following:
getline()).If no characters were extracted, callssetstate(failbit).
All versions set the value ofgcount() to the number of characters extracted.
Contents |
| ch | - | reference to the character to write the result to |
| s | - | pointer to the character string to store the characters to |
| count | - | size of character string pointed to bys |
| delim | - | delimiting character to stop the extraction at. It is not extracted and not stored |
| strbuf | - | stream buffer to read the content to |
If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.
#include <iostream>#include <sstream> int main(){std::istringstream s1("Hello, world.");char c1= s1.get();// reads 'H'std::cout<<"after reading "<< c1<<", gcount() == "<< s1.gcount()<<'\n'; char c2; s1.get(c2);// reads 'e'char str[5]; s1.get(str,5);// reads "llo,"std::cout<<"after reading "<< str<<", gcount() == "<< s1.gcount()<<'\n'; std::cout<< c1<< c2<< str; s1.get(*std::cout.rdbuf());// reads the rest, not including '\n'std::cout<<"\nAfter the last get(), gcount() == "<< s1.gcount()<<'\n';}
Output:
after reading H, gcount() == 1after reading llo,, gcount() == 4Hello, world.After the last get(), gcount() == 7
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 370 | C++98 | the effect of overload(5) wasget(s, count, widen('\n')), which is the effect of overload(3) | corrected to get(strbuf, widen('\n')) |
| LWG 531 | C++98 | overloads(3,4) could not handle the case wherecount is non-positive | no character is extracted in this case |
| extracts blocks of characters (public member function)[edit] | |
| extracts formatted data (public member function)[edit] | |
| extracts characters and character arrays (function template)[edit] |