Skip to content. Skip to navigation

ICTP Portal

Sections
You are here: Home Manuals on-line PGI Compiler pgC_lib basic_stringstream
Personal tools
Document Actions

basic_stringstream



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

    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 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.

Weather
No information available
 

Powered by Plone This site conforms to the following standards: