istream::get istream
  cplusplus.com  
 
int get();
istream& get (char& c );
istream& get (char* s, streamsize n );
istream& get (char* s, streamsize n, char delim );
istream& get (streambuf* sb);
istream& get (streambuf* sb, char delim );

Extract unformatted data from stream.
  These member functions perform unformatted input. The effect depends on the variation used:

int get();
extracts a character from the stream and returns its value.
 
istream& get (char& c );
extracts a character from the stream and stores it in c.
 
istream& get (char* s, streamsize n );
istream& get (char* s, streamsize n, char delim );
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 not extracted from the input stream and remains as the next character to be extracted. Use getline if you want this character to be extracted (and discarded).
An ending null character is automatically appended at the end of the content stored in s.
 
istream& get (streambuf* sb);
istream& get (streambuf* sb, char delim );
extracts characters from the stream and inserts them in stream buffer sb. Characters are extacted until either the delimiter (parameter delim or '\n' if not speciffied) if found, or it the end of file or any error occurs in the input or output sequences.

Parameters.

c
A reference to a character.
s
A pointer to an array of characters.
n
The maximum number of characters to store, including the ternimating null character.
This is an integer value of type streamsize.
delim
The delimiter. The operation of extracting succesive characters is stopped when the delimiter is read. This parameter is optional, if not specified the function considers '\n' the delimiter.
sb
Output stream buffer: A pointer to an object of class streambuf or any derived class.

Return Value.
  If above is not specified otherwise, the function returns *this

Example.

// istream get
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  char c, str[256];
  ifstream is;

  cout << "Enter the name of an existing text file: ";
  cin.get (str,256);

  is.open (str);        // open file

  while (is.good())     // loop while extraction from file is possible
  {
    c = is.get();       // get character from file
    cout << c;
  }

  is.close();           // close file

  return 0;
}
  This example prompts for the name of an existing text file and prints its content on screen.

Basic template member declarations ( basic_istream<charT,traits> ):
typedef charT char_type;
int_type get();
basic_istream& get (char_type& c );
basic_istream& get (char_type* s, streamsize n );
basic_istream& get (char_type* s, streamsize n, char_type delim );
basic_istream& get (basic_streambuf<char_type,traits>* sb);
basic_istream& get (basic_streambuf<char_type,traits>* sb, char_type delim );

See also.
  getline, ignore, gcount
  istream class


© The C++ Resources Network, 2001