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

Extracts characters from stream until end of line or the specified delimiter delim.

# Declarations

basic_istream& getline( char_type* s, std::streamsize count );
basic_istream& getline( char_type* s, std::streamsize count, char_type delim );

# Parameters

# Return value

*this

# Notes

Because condition #2 is tested before condition #3, the input line that exactly fits the buffer does not trigger failbit.

Because the terminating character is counted as an extracted character, an empty input line does not trigger failbit.

# Example

#include <array>
#include <iostream>
#include <sstream>
#include <vector>
 
int main()
{
    std::istringstream input("abc|def|gh");
    std::vector<std::array<char, 4>> v;
 
    // note: the following loop terminates when std::ios_base::operator bool()
    // on the stream returned from getline() returns false
    for (std::array<char, 4> a; input.getline(&a[0], 4, '|');)
        v.push_back(a);
 
    for (auto& a : v)
        std::cout << &a[0] << '\n';
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 531C++98std::getline could not handle thecase where count is non-positiveno character isextracted in this case

# See also