std::basic_istream<CharT,Traits>::get
Min standard notice:
Extracts character or characters from stream.
# Declarations
int_type get();
basic_istream& get( char_type& ch );
basic_istream& get( char_type* s, std::streamsize count );
basic_istream& get( char_type* s, std::streamsize count, char_type delim );
basic_istream& get( basic_streambuf& strbuf );
basic_istream& get( basic_streambuf& strbuf, char_type delim );
# Parameters
ch: reference to the character to write the result tos: pointer to the character string to store the characters tocount: size of character string pointed to by sdelim: delimiting character to stop the extraction at. It is not extracted and not storedstrbuf: stream buffer to read the content to
# Example
#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';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 370 | C++98 | the effect of overload (5) was get(s, count, widen(’\n’)),which is the effect of overload (3) | corrected toget(strbuf, widen(’\n’)) |
| LWG 531 | C++98 | overloads (3,4) could not handle thecase where count is non-positive | no character isextracted in this case |