United States    
COMPAQ STORE | PRODUCTS | SERVICES | SUPPORT
| CONTACT US | SEARCH
C++
stringstream (3C++std) - Tru64 UNIX
Standard C++ Library
Copyright 1996, Rogue Wave Software, Inc.

NAME

  basic_stringstream

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
     The type char_type is a synonym for the template parameter charT.

  int_type
     The type int_type is a synonym of type traits::in_type.

  ios_type
     The type ios_type is an instantiation of class basic_ios on type charT.

  off_type
     The type off_type is a synonym of type traits::off_type.

  pos_type
     The type pos_type is a synonym of type traits::pos_type.

  sb_type
     The type sb_type is an instantiation of class basic_stringbuf on type
     charT.

  string_type
     The type string_type is an instantiation of class basic_string on type
     charT.

  stringstream
     The type stringstream is an instantiation of class basic_stringstream on
     type char:

       typedef basic_stringstream<char> stringstream;

  traits_type
     The type traits_type is a synonym for the template parameter traits.

  wstringstream
     The type wstringstream is an instantiation of class basic_stringstream
     on type wchar_t:

       typedef basic_stringstream<wchar_t> wstringstream;

CONSTRUCTORS

  explicit basic_stringstream(ios_base::openmode which =
                    ios_base::in | ios_base::out);
                       Constructs an object of class basic_stringstream,
                       initializing the base class basic_iostream with the
                       associated string buffer. The string buffer is
                       initialized by calling the basic_stringbuf constructor
                       basic_stringbuf<charT,traits,Allocator>(which).

  explicit basic_stringstream(const string_type& str,
                    ios_base::openmode which =
                    ios_base::in | ios_base::out);
                       Constructs an object of class basic_stringstream,
                       initializing the base class basic_iostream with the
                       associated string buffer. The string buffer is
                       initialized by calling the basic_stringbuf constructor
                       basic_stringbuf<charT,traits,Allocator>(str,which).

DESTRUCTOR

  virtual ~basic_stringstream();
     Destroys an object of class basic_stringstream.

MEMBER FUNCTIONS

  basic_stringbuf<charT,traits,Allocator>*
  rdbuf() const;
     Returns a pointer to the basic_stringbuf associated with the stream.

  string_type
  str() const;
     Returns a string object of type string_type whose contents is a copy of
     the underlying buffer contents.

  void
  str(const string_type& str);
     Clears the string buffer and copies the string object str into it. If
     the opening mode is in, initializes the input sequence to point at the
     first character of the buffer. If the opening mode is out, initializes
     the output sequence to  point at the first character of the buffer. If
     the opening mode is out | app, initializes the output sequence to point
     at the last character of the buffer.

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 seconf 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++std), ios_base(3C++std), basic_ios(3C++std),
  basic_stringbuf(3C++std), basic_string(3C++std),
  basic_istringstream(3C++std), 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
  

1.800.AT.COMPAQ

privacy and legal statement