cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : streambuf : sgetn
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
streambuf
· streambuf::streambuf
· streambuf::~streambuf
public members:
· streambuf::getloc
· streambuf::in_avail
· streambuf::pubimbue
· streambuf::pubseekoff
· streambuf::pubseekpos
· streambuf::pubsetbuf
· streambuf::pubsync
· streambuf::sbumpc
· streambuf::sgetc
· streambuf::sgetn
· streambuf::snextc
· streambuf::sputbackc
· streambuf::sputc
· streambuf::sputn
· streambuf::sungetc
protected members:
· streambuf::eback
· streambuf::egptr
· streambuf::epptr
· streambuf::gbump
· streambuf::gptr
· streambuf::pbase
· streambuf::pbump
· streambuf::pptr
· streambuf::setg
· streambuf::setp
virtual prot. members:
· streambuf::imbue
· streambuf::overflow
· streambuf::pbackfail
· streambuf::seekoff
· streambuf::seekpos
· streambuf::setbuf
· streambuf::showmanyc
· streambuf::sync
· streambuf::uflow
· streambuf::underflow
· streambuf::xsgetn
· streambuf::xsputn

-

streambuf::sgetn public member function
streamsize sgetn ( const char * s, streamsize n );

Get sequence of characters

Calls the protected virtual member xsgetn, which gets up to n characters from the input sequence and stores them in the array pointed by s.

If less than n characters are available in the input sequence the function returns all the available characters, as if successive calls to sbumpc were made until an EOF (or traits::eof() for other traits) was returned.

Parameters

s
Pointer to a block of memory where the character sequence is to be stored.
n
Number of characters to be gotten. This is an integer value of type streamsize.

Return Value

The number of characters gotten, returned as a value of type streamsize.

Example

// read a file buffer - sgetn () example
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  char content[11];
  streambuf * pbuf;
  ifstream istr ("test.txt");

  pbuf = istr.rdbuf();

  pbuf->sgetn (content,10);

  istr.close();

  cout.write (content,10);

  return 0;
}

This example gets the first ten characters of the file buffer and prints them out.

Basic template member declaration

( basic_streambuf<charT,traits> )
streamsize sgetn ( char_type* s, streamsize n );

See also

streambuf::sgetc Get current character (public member function)
streambuf::sputn Write a sequence of characters (public member function)
streambuf::sputc Store character at current put position and increase put pointer (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us