Click on the banner to return to the class reference home page.

strstreambuf


strstreambufbasic_streambuf

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <strstream> 
class strstreambuf
: public basic_streambuf<char>

Description

The class strstreambuf is derived from basic_streambuf specialized on type char to associate possibly the input sequence and possibly the output sequence with a tiny character array, whose elements store arbitrary values.

Each object of type strstreambuf controls two character sequences:

Note: see basic_streambuf.

The two sequences are related to each other, but are manipulated separately. This means that you can read and write characters at different positions in objects of type strstreambuf without any conflict (in opposition to the basic_filebuf objects).

The underlying array has several attributes:

Interface

class strstreambuf 
: public basic_streambuf<char> {

 public:

  typedef char_traits<char>          traits;
  typedef basic_ios<char, traits>    ios_type;

  typedef char                       char_type;
  typedef typename traits::int_type  int_type;
  typedef typename traits::pos_type  pos_type;
  typedef typename traits::off_type  off_type;

  explicit strstreambuf(streamsize alsize = 0);
  strstreambuf(void *(*palloc)(size_t), void (*pfree)(void *));
  strstreambuf(char *gnext, streamsize n, char *pbeg = 0);

  strstreambuf(unsigned char *gnext, streamsize n,
               unsigned char *pbeg = 0);
  strstreambuf(signed char *gnext, streamsize n,
               signed char *pbeg = 0);

  strstreambuf(const char *gnext, streamsize n);
  strstreambuf(const unsigned char *gnext, streamsize n);
  strstreambuf(const signed char *gnext, streamsize n);

  virtual ~strstreambuf();

  void freeze(bool f = 1);

  char *str();
  int pcount() const;

 protected:

  virtual int_type overflow(int_type c = traits::eof());

  virtual int_type pbackfail(int_type c = traits::eof());

  virtual int_type underflow();

  virtual pos_type seekoff(off_type, ios_type::seekdir way,
                           ios_type::openmode which =
                           ios_type::in | ios_type::out);

  virtual pos_type seekpos(pos_type sp, ios_type::openmode which =
                           ios_type::in | ios_type::out);

  virtual streambuf* setbuf(char *s, streamsize n);

  virtual streamsize xsputn(const char_type* s, streamsize n);

};

Types

char_type
int_type
ios_type
off_type
pos_type
traits

Constructors

explicit strstreambuf(streamsize alsize = 0);
strstreambuf(void* (*palloc)(size_t),
             void (*pfree)(void*));
strstreambuf(char* gnext, streamsize n,
             char* pbeg = 0);
strstreambuf(signed char* gnext, streamsize n,
             signed char* pbeg = 0);
strstreambuf(unsigned char* gnext, streamsize n,
             unsigned char* pbeg = 0);
strstreambuf(const char* gnext, streamsize n);
strstreambuf(const signed char* gnext, streamsize n);
strstreambuf(const unsigned char* gnext, streamsize n);

Destructors

virtual ~strstreambuf();

Member Functions

void 
freeze(bool freezefl = 1);
int_type 
overflow( int_type c = traits::eof() );
int_type 
pbackfail( int_type c = traits::eof() );
int 
pcount() const;
pos_type 
seekoff(off_type off, ios_base::seekdir way,
        ios_base::openmode which = 
        ios_base::in | ios_base::out);
pos_type 
seekpos(pos_type sp,ios_base::openmode which = 
        ios_base::in | ios_base::out);
strstreambuf* 
setbuf(char* s, streamsize n);
char* 
str();
int_type 
underflow();
streamsize 
xsputn(const char_type* s, streamsize n);

Examples

//
// stdlib/examples/manual/strstreambuf.cpp
//
#include<iostream>
#include<strstream>
#include<iomanip>

void main ( )
{
  using namespace std;

  // create a read/write strstream object
  // and attach it to an ostrstream object
  ostrstream out;

  // tie the istream object to the ostrstream object
  istream in(out.rdbuf());   

  // output to out
  out << "anticonstitutionellement is a big word !!!";

  // create a NTBS 
  char *p ="Le rat des villes et le rat des champs";

  // output the NTBS
  out << p << endl;   

  // resize the buffer
  if ( out.rdbuf()->pubsetbuf(0,5000) )
   cout << endl << "Success in allocating the buffer" << endl;

  // output the all buffer to stdout
  cout << in.rdbuf( );

  // output the decimal conversion of 100 in hex
  // with right padding and a width field of 200
  out << dec << setfill('!') << setw(200) << 0x100 << endl;  
  
  // output the content of the input sequence to stdout
  cout << in.rdbuf( ) << endl;

  // number of elements in the output sequence
  cout << out.rdbuf()->pcount() << endl;

  // resize the buffer to a minimum size
  if ( out.rdbuf()->pubsetbuf(0,out.rdbuf()->pcount()) )
   cout << endl << "Success in resizing the buffer" << endl;

  // output the content of the all array object
  cout << out.rdbuf()->str() << endl;

 }

See Also

char_traits(3C++), ios_base(3C++), basic_ios(3C++), basic_streambuf(3C++), istrstream(3c++), ostrstream(3C++), strstream(3c++)

Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Annex D Compatibility features Section D.5

Standards Conformance

ANSI X3J16/ISO WG21 Joint C++ Committee


©Copyright 1996, Rogue Wave Software, Inc.