istream::getline
istream& getline (char* s, streamsize n ); istream& getline (char* s, streamsize n, char delim ); | istream |
cplusplus.com |
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.
Parameters.
Return Value.
The function returns *this
Example.
// 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