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

basic_stringstream


basic_ostream basic_stringstreambasic_iostream basic_iosios_base basic_istream

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

Synopsis

#include <sstream> 
template<class charT, class traits = char_traits<charT>,
         class Allocator = allocator<void> >
class basic_stringstream
: public basic_iostream<charT, traits>

Description

The template class basic_stringstream<charT,traits,Allocator> provides functionality to read and write to an array in memory. It supports writing and reading objects of class basic_string<charT,traits,Alocator>. It uses a basic_stringbuf object to control the associated storage. It inherits from basic_iostream and therefore can use all the formatted and unformatted output and input functions.

Interface

template<class charT, class traits = char_traits<charT>,
         class Allocator = allocator<void> >
class basic_stringstream 
: public basic_iostream<charT, traits> {

 public:

  typedef basic_stringbuf<charT, traits, Allocator>  sb_type;
  typedef basic_ios<charT, traits>                   ios_type;

  typedef basic_string<charT, traits, Allocator>     string_type;

  typedef traits                            traits_type;
  typedef charT                             char_type;
  typedef typename traits::int_type         int_type;
  typedef typename traits::pos_type         pos_type;
  typedef typename traits::off_type         off_type;

  explicit basic_stringstream(ios_base::openmode which = 
                              ios_base::out | ios_base::in);

  explicit basic_stringstream(const string_type& str,
                              ios_base::openmode which =
                              ios_base::out | ios_base::in);

  virtual ~basic_stringstream();

  basic_stringbuf<charT,traits,Allocator> *rdbuf() const;
  string_type str() const;

  void str(const string_type& str);

};

Types

char_type
int_type
ios_type
off_type
pos_type
sb_type
string_type
stringstream
traits_type
wstringstream

Constructors

explicit basic_stringstream(ios_base::openmode which =
                   ios_base::in | ios_base::out);
explicit basic_stringstream(const string_type& str,
                   ios_base::openmode which =
                   ios_base::in | ios_base::out);

Destructor

virtual ~basic_stringstream();

Member Functions

basic_stringbuf<charT,traits,Allocator>* 
rdbuf() const;
string_type 
str() const;
void 
str(const string_type& str);

Examples

//
// stdlib/examples/manual/stringstream.cpp
//
#include<iostream>
#include<sstream>

void main ( )
{
  using namespace std;

  // create a bi-directional wstringstream object 
  wstringstream inout;

  // output characters
  inout << L"Das ist die rede von einem man" << endl;
  inout << L"C'est l'histoire d'un home" << endl;
  inout << L"This is the story of a man" << endl;

  wchar_t p[100];

  // extract the first line
  inout.getline(p,100);

  // output the first line to stdout
  wcout << endl << L"Deutch :" << endl;
  wcout << p;

  // extract the second line
  inout.getline(p,100);

  // output the second line to stdout
  wcout << endl << L"Francais :" << endl;
  wcout << p;

  // extract the third line
  inout.getline(p,100);

  // output the third line to stdout
  wcout << endl << L"English :" << endl;
  wcout << p;
 
  // output the all content of the
  //wstringstream object to stdout
  wcout << endl << endl << inout.str();
}

See Also

char_traits(3C++), ios_base(3C++), basic_ios(3C++), basic_stringbuf(3C++), basic_string(3C++), basic_istringstream(3C++), basic_ostringstream(3c++)

Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Section 27.7.3

Standards Conformance

ANSI X3J16/ISO WG21 Joint C++ Committee


©Copyright 1996, Rogue Wave Software, Inc.