istream& getline (char* s, streamsize n );
istream& getline (char* s, streamsize n, char delim );

Get a line from stream.
  Extracts characters from the stream and stores them into successive locations in the array pointed by s.
  Characters are extracted until either (n - 1) characters have been extracted, the delimiter (parameter delim or '\n' if not specified) is found, or if the end of file or any error occurs in the input sequence.
  If the delimiter is found it is extracted but not not stored. Use get if you don't want this character to be extracted.
  An ending null character is automatically appended after the data stored in s.


A pointer to an array of characters.
The maximum number of characters to store, including the ternimating null character.
This is an integer value of type streamsize.
The delimiter. The operation of extracting succesive characters is stopped when delimiter is read. This parameter is optional, if not specified the function considers '\n' the delimiter.

Return Value.
  The function returns *this


// istream getline
#include <iostream>
using namespace std;

int main () {
  char name[256], title[256];

  cout << "Enter your name: ";
  cin.getline (name,256);

  cout << "Enter your favourite movie: ";
  cin.getline (title,256);

  cout << name << "'s favourite movie is " << title;

  return 0;
  This example demonstrates how to get line inputs from the standard input ( cin ).

Basic template member declarations ( basic_istream<charT,traits> ):
typedef charT char_type;
basic_istream& getline (char_type* s, streamsize n );
basic_istream& getline (char_type* s, streamsize n, char_type delim );

See also.
  get, ignore, gcount
  istream class

© The C++ Resources Network, 2001