
Module: Standard C++ Library Library: Input/output
basic_ostream strstream
basic_iostream
basic_ios
ios_base
basic_istream
|
char_type freeze() int_type |
off_type pcount() pos_type |
rdbuf() str() strstream() |
traits_type ~strstream() |
Class that reads and writes to an array in memory
#include <strstream>
namespace std {
class strstream;
}
The class strstream reads and writes to an array in memory. It uses a private strstreambuf object to control the associated array. It inherits from basic_iostream and therefore can use all the formatted and unformatted output and input functions.
NOTE -- This is a deprecated feature and might not be available in future versions.
namespace std {
class strstream
: public basic_iostream<char> {
public:
typedef char char_type;
typedef char_traits<char_type> traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
strstream();
strstream(char *s, int n,
ios_base::openmode =
ios_base::out | ios_base::in);
void freeze(int freezefl = 1);
int pcount() const;
virtual ~strstream();
strstreambuf *rdbuf() const;
char *str();
};
}
char_type
The type char_type is a synonym of type char.
int_type
The type int_type is a synonym of type traits_type::in_type.
off_type
The type off_type is a synonym of type traits_type::off_type.
pos_type
The type pos_type is a synonym of type traits_type::pos_type.
traits_type
The type traits_type is a synonym of type char_traits<char>.
strstream();
Constructs an object of class strstream, initializing the base class basic_iostream with the associated strstreambuf object. The strstreambuf object is initialized by calling its default constructor strstreambuf().
strstream(char* s, int n, ios_base::openmode
mode = ios_base::out | ios_base::in);
Constructs an object of class strstream, initializing the base class basic_iostream with the associated strstreambuf object. The strstreambuf object is initialized by calling one of two constructors:
If mode & app == 0, calls strstreambuf(s,n,s)
Otherwise calls strstreambuf(s,n,s + ::strlen(s))
virtual ~strstream();
Destroys an object of class strstream.
void freeze(bool freezefl = true);
Calls rdbuf()->freeze(freezefl).
int pcount() const;
Returns rdbuf()->pcount().
strstreambuf* rdbuf() const;
Returns a pointer to the strstreambuf object associated with the stream.
char* str();
Returns rdbuf()->str().
//
// strstream.cpp
//
#include <iostream> // for cout, endl
#include <strstream> // for sstream
int main ()
{
// create a bi-directional strstream object
std::strstream inout;
// write out three lines to the stream
inout << "Dieses ist die Geschichte eines Mannes.\n"
<< "C'est l'histoire d'un homme.\n"
<< "This is the story of a man." << std::endl;
char line [80];
// extract the first line
inout.getline (line, sizeof line);
// output the first line to stdout
std::cout << "\nDeutsch:\n" << line;
// extract the second line
inout.getline (line, sizeof line);
// output the second line to stdout
std::cout << "\nFrançais:\n" << line;
// extract the third line
inout.getline (line, sizeof line);
// output the third line to stdout
std::cout << "\nEnglish:\n" << line << std::endl;
// output the contents of the stream object to stdout
std::cout << std::endl << inout.str () << std::endl;
return 0;
}
Program Output:
Deutsch: Dieses ist die Geschichte eines Mannes. Francais: C'est l'histoire d'un homme. English: This is the story of a man. Dieses ist die Geschichte eines Mannes. C'est l'histoire d'un homme. This is the story of a man.
char_traits, ios_base, basic_ios, strstreambuf, istrstream, ostrstream
Deprecated. See ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Annex D Compatibility features Section D.7.4
Copyright (c) 1994-2006 Rogue Wave Software, a Quovadx Division.
Licensed under the Apache License, Version 2.0.
Contact Rogue Wave about documentation or support issues. You can also seek help from other developers through the Apache stdcxx community (see below).