std::basic_istream<CharT,Traits>::get

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

# 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

DRApplied toBehavior as publishedCorrect behavior
LWG 370C++98the effect of overload (5) was get(s, count, widen(’\n’)),which is the effect of overload (3)corrected toget(strbuf, widen(’\n’))
LWG 531C++98overloads (3,4) could not handle thecase where count is non-positiveno character isextracted in this case

# See also