blob: 517f8d5d065c0a0962575c14f8801fe52944813c [file] [log] [blame]
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed
with this work for additional information regarding copyright
ownership. The ASF licenses this file to you under the Apache
License, Version 2.0 (the License); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied. See the License for the specific language governing
permissions and limitations under the License.
Copyright 1999-2007 Rogue Wave Software, Inc.
-->
<HTML>
<HEAD>
<TITLE>strstream</TITLE>
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
<BODY BGCOLOR=#FFFFFF>
<A HREF="strstream-h.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="strstreambuf.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library Reference Guide</B></DIV>
<H2>strstream</H2>
<P><B>Library:</B>&nbsp;&nbsp;<A HREF="2-11.html">Input/output</A></P>
<PRE><HR> <IMG SRC="images/inherits.gif"> <B><I><A HREF="basic-ostream.html">basic_ostream</A></I></B>
<B><I>strstream</I></B> <IMG SRC="images/inherits.gif"> <B><I><A HREF="basic-iostream.html">basic_iostream</A></I></B> <IMG SRC="images/inherits.gif"> <B><I><A HREF="basic-ios.html">basic_ios</A></I></B> <IMG SRC="images/inherits.gif"> <B><I><A HREF="ios-base.html">ios_base</A></I></B>
<IMG SRC="images/inherits.gif"> <B><I><A HREF="basic-istream.html">basic_istream</A></I></B> <HR></PRE>
<UL>
<LI><A HREF="#sec1">Local Index</A></LI>
<LI><A HREF="#sec2">Summary</A></LI>
<LI><A HREF="#sec3">Synopsis</A></LI>
<LI><A HREF="#sec4">Description</A></LI>
<LI><A HREF="#sec5">Interface</A></LI>
<LI><A HREF="#sec6">Member Types</A></LI>
<LI><A HREF="#sec7">Constructors</A></LI>
<LI><A HREF="#sec8">Destructors</A></LI>
<LI><A HREF="#sec9">Member Functions</A></LI>
<LI><A HREF="#sec10">Example</A></LI>
<LI><A HREF="#sec11">See Also</A></LI>
<LI><A HREF="#sec12">Standards Conformance</A></LI>
</UL>
<A NAME="sec1"><H3>Local Index</H3></A>
<H4>Members</H4>
<UL><TABLE CELLPADDING=3>
<TR><TD VALIGN=top>
<A HREF="#idx1194">char_type</A><BR>
<A HREF="#idx1202">freeze()</A><BR>
<A HREF="#idx1195">int_type</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx1196">off_type</A><BR>
<A HREF="#idx1203">pcount()</A><BR>
<A HREF="#idx1197">pos_type</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx1204">rdbuf()</A><BR>
<A HREF="#idx1205">str()</A><BR>
<A HREF="#idx1199">strstream()</A><BR>
</TD>
<TD VALIGN=top><A HREF="#idx1198">traits_type</A><BR>
<A HREF="#idx1201">~strstream()</A><BR>
</TD></TR>
</TABLE></UL>
<A NAME="sec2"><H3>Summary</H3></A>
<P>Class that reads and writes to an array in memory</P>
<A NAME="sec3"><H3>Synopsis</H3></A>
<PRE>#include &lt;strstream&gt;
namespace std {
class strstream;
}
</PRE>
<A NAME="sec4"><H3>Description</H3></A>
<P>The class <B><I>strstream</I></B> reads and writes to an array in memory. It uses a private <B><I><A HREF="strstreambuf.html">strstreambuf</A></I></B> object to control the associated array. It inherits from <B><I><A HREF="basic-iostream.html">basic_iostream</A></I></B> and therefore can use all the formatted and unformatted output and input functions.</P>
<BLOCKQUOTE><HR><B>
NOTE -- This is a deprecated feature and might not be available in future versions.
</B><HR></BLOCKQUOTE>
<A NAME="sec5"><H3>Interface</H3></A>
<UL><PRE>namespace std {
class strstream
: public basic_iostream&lt;char&gt; {
public:
typedef char char_type;
typedef char_traits&lt;char_type&gt; 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();
};
}
</PRE></UL>
<A NAME="sec6"><H3>Member Types</H3></A>
<A NAME="idx1194"></A><PRE><B>char_type</B></PRE>
<UL>
<P>The type <SAMP>char_type</SAMP> is a synonym of type <SAMP>char</SAMP>.</P>
</UL>
<A NAME="idx1195"></A><PRE><B>int_type</B></PRE>
<UL>
<P>The type <SAMP>int_type</SAMP> is a synonym of type<SAMP> traits_type::in_type</SAMP>.</P>
</UL>
<A NAME="idx1196"></A><PRE><B>off_type</B></PRE>
<UL>
<P>The type <SAMP>off_type</SAMP> is a synonym of type <SAMP>traits_type::off_type</SAMP>.</P>
</UL>
<A NAME="idx1197"></A><PRE><B>pos_type</B></PRE>
<UL>
<P>The type <SAMP>pos_type</SAMP> is a synonym of type <SAMP>traits_type::pos_type</SAMP>.</P>
</UL>
<A NAME="idx1198"></A><PRE><B>traits_type</B></PRE>
<UL>
<P>The type <SAMP>traits_type</SAMP> is a synonym of type <SAMP>char_traits&lt;char&gt;</SAMP>.</P>
</UL>
<A NAME="sec7"><H3>Constructors</H3></A>
<A NAME="idx1199"></A><PRE><B>strstream</B>();</PRE>
<UL>
<P>Constructs an object of class <B><I>strstream</I></B>, initializing the base class <B><I><A HREF="basic-iostream.html">basic_iostream</A></I></B> with the associated <B><I><A HREF="strstreambuf.html">strstreambuf</A></I></B> object. The <B><I>strstreambuf</I></B> object is initialized by calling its default constructor <SAMP>strstreambuf()</SAMP>.</P>
</UL>
<A NAME="idx1200"></A><PRE><B>strstream</B>(char* s, int n, ios_base::openmode
mode = ios_base::out | ios_base::in); </PRE>
<UL>
<P>Constructs an object of class <B><I>strstream</I></B>, initializing the base class <B><I><A HREF="basic-iostream.html">basic_iostream</A></I></B> with the associated <B><I><A HREF="strstreambuf.html">strstreambuf</A></I></B> object. The <B><I>strstreambuf</I></B> object is initialized by calling one of two constructors:</P>
<UL>
<LI><P CLASS="LIST">If <SAMP>mode &amp; app == 0</SAMP>, calls <SAMP>strstreambuf(s,n,s)</SAMP></P></LI>
<LI><P CLASS="LIST">Otherwise calls <SAMP>strstreambuf(s,n,s + ::strlen(s))</SAMP></P></LI>
</UL>
</UL>
<A NAME="sec8"><H3>Destructors</H3></A>
<A NAME="idx1201"></A><PRE>virtual <B>~strstream</B>();</PRE>
<UL>
<P>Destroys an object of class <B><I>strstream</I></B>. </P>
</UL>
<A NAME="sec9"><H3>Member Functions</H3></A>
<A NAME="idx1202"></A><PRE>void
<B>freeze</B>(bool freezefl = true); </PRE>
<UL>
<P>Calls <SAMP>rdbuf()-&gt;freeze(freezefl)</SAMP>.</P>
</UL>
<A NAME="idx1203"></A><PRE>int
<B>pcount</B>() const; </PRE>
<UL>
<P>Returns <SAMP>rdbuf()-&gt;pcount()</SAMP>.</P>
</UL>
<A NAME="idx1204"></A><PRE>strstreambuf*
<B>rdbuf</B>() const; </PRE>
<UL>
<P>Returns a pointer to the <B><I><A HREF="strstreambuf.html">strstreambuf</A></I></B> object associated with the stream.</P>
</UL>
<A NAME="idx1205"></A><PRE>char*
<B>str</B>();</PRE>
<UL>
<P>Returns <SAMP>rdbuf()-&gt;str()</SAMP>.</P>
</UL>
<A NAME="sec10"><H3>Example</H3></A>
<UL><PRE>//
// strstream.cpp
//
#include &lt;iostream&gt; // for cout, endl
#include &lt;strstream&gt; // for sstream
int main ()
{
// create a bi-directional strstream object
std::strstream inout;
// write out three lines to the stream
inout &lt;&lt; "Dieses ist die Geschichte eines Mannes.\n"
&lt;&lt; "C'est l'histoire d'un homme.\n"
&lt;&lt; "This is the story of a man." &lt;&lt; std::endl;
char line [80];
// extract the first line
inout.getline (line, sizeof line);
// output the first line to stdout
std::cout &lt;&lt; "\nDeutsch:\n" &lt;&lt; line;
// extract the second line
inout.getline (line, sizeof line);
// output the second line to stdout
std::cout &lt;&lt; "\nFran&ccedil;ais:\n" &lt;&lt; line;
// extract the third line
inout.getline (line, sizeof line);
// output the third line to stdout
std::cout &lt;&lt; "\nEnglish:\n" &lt;&lt; line &lt;&lt; std::endl;
// output the contents of the stream object to stdout
std::cout &lt;&lt; std::endl &lt;&lt; inout.str () &lt;&lt; std::endl;
return 0;
}
Program Output:
</PRE></UL>
<UL><PRE>
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.
</PRE></UL>
<A NAME="sec11"><H3>See Also</H3></A>
<P><B><I><A HREF="char-traits.html">char_traits</A></I></B>, <B><I><A HREF="ios-base.html">ios_base</A></I></B>, <B><I><A HREF="basic-ios.html">basic_ios</A></I></B>, <B><I><A HREF="strstreambuf.html">strstreambuf</A></I></B>, <B><I><A HREF="istrstream.html">istrstream</A></I></B>, <B><I><A HREF="ostrstream.html">ostrstream</A></I></B></P>
<A NAME="sec12"><H3>Standards Conformance</H3></A>
<P><I>Deprecated. See ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, </I>Annex D Compatibility features Section D.7.4</P>
<BR>
<HR>
<A HREF="strstream-h.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="strstreambuf.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A>
<!-- Google Analytics tracking code -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-1775151-1";
urchinTracker();
</script>
<!-- end of Google Analytics tracking code -->
</BODY>
</HTML>