⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osstream.htm

📁 这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明
💻 HTM
字号:
<html>
<head>
<title> The basic_ostringstream Class</title>
</head>

<body bgcolor="#FFFFFF">

<img src="oststban.gif">

<pre>
<font size=5>Class Name</font>            basic_ostringstream

<font size=5>Header File</font>           &lt;sstream&gt;

<font size=5>Classification</font>      Input/Output (Memory Class)
</pre>
<a href="osstream.htm#diagram">Class Relationship Diagram</a><br>
<br>
<a href="osstream.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>


<a href="strbuf.htm">basic_stringbuf</a>

<h1>Methods</h1> 

<pre>
<a href="osstream.htm#ostring1">explicit basic_ostringstream(ios_base::openmode OMode = ios_base::in)</a><br>
<a href="osstream.htm#ostring2">explicit basic_ostringstream(const basic_string<charT,traits,Allocator>& Str,ios_base::openmode OMode = ios_base::in)</a><br>
<a href="osstream.htm#rdbuf">basic_stringbuf<charT,traits,Allocator>* rdbuf() const</a><br>
<a href="streabuf.htm#str1">basic_string<charT,traits,Allocator> str() const</a><br>
<a href="streabuf.htm#str2">void str(const basic_string<charT,traits,Allocator>& Str)</a><br>
</pre>

<a href="osstream.htm#example"><h2>Example</h2></a>
<hr>
<a name="desc"><h3>Class Description</h3></a>
<p>
The basic_ostringstream class implements the functionality of an object oriented input memory device.
Whereas the cout type basic_ostream object is normally tied to the console, and the ofstream 
class is connected to a file, or a device that is recognized as a file.  The basic_ostringstream 
class is connected to a block of memory, or a character array.  The basic_ostringstream 
class is a model of a character, or byte array. The ostringstream class is derived from the
basic_ostream class. The standard typedef for basic_ostringstream is <i>ostringstream</i>.
</p>
<p>
Whereas the basic_ostream class has a basic_streambuf component, and the ofstream has a filebuf
component, the ostringstream class has a stringbuf component.  The stringbuf component is a
specialized basic_streambuf.  It is derived from basic_streambuf.  The stringbuf component is
connected to a character array, as opposed to a file.  The source of a stringbuf is intended to
be a memory device.  The programmer can have direct access to the ostringstream memory device
through the stringbuf component.  The stringbuf component can be reached by the rdbuf() member
function.
</p>                      
<hr>


<pre>                                
<a name="ostring1">Method            basic_ostringstream()</a>

Access            Public

Classification    Constructor

Syntax            explicit basic_ostringstream(ios_base::openmode OMode = ios_base::out)

Parameters        OMode is the open mode the buffer will be constructed with.
                  Basic open modes are:

                                Open Mode       Function
                                ________________________________________
                                app             append
                                ate             open at end
                                out             open for writing
                                trunc           erase buffer start at 0
                                ________________________________________
                               

Return            None

</pre>
<hr>

<pre>                                
<a name="ostring2">Method            basic_ostringstream()</a>

Access            Public

Classification    Constructor

Syntax            explicit basic_ostringstream(const basic_string<charT,traits,Allocator>& Str,ios_base::openmode OMode = ios_base::out)

Parameters        OMode is the open mode the buffer will be constructed with.
                  Basic open modes are:

                                Open Mode       Function
                                ________________________________________
                                app             append
                                ate             open at end
                                out             open for writing
                                trunc           erase buffer start at 0
                                ________________________________________

                 Str is a reference  to a character buffer that will be used as the put area for the
                 ostringstream object.
                               

Return            None

</pre>

<h3>Description</h3>       
<p>

This basic_ostringstream() method constructs a basic_ostringstream object. It constructs a
stream that is uses Str as its buffer or put area.
</p>
<hr>


<pre>                                
<a name="rdbuf">Method            rdbuf()</a>

Access            Public

Classification    Accessor

Syntax            basic_filebuf&lt;charT,traits&gt;* rdbuf() const

Parameters        None

Return            Returns a pointer to the associated streambuf object.

</pre>

<h3>Description</h3>       
<p>
The rdbuf() method returns a pointer to the associated streambuf object.
</p>
<hr>

<p>
<a name="diagram"><h2>The Class Relationship Diagram of basic_ostringstream</h2></a>
<img src="ostrgstr.gif">
</p>
<hr>

<a name="example"></a>
<img src="lego.gif">

<pre>
    1   #include &lt;iostream&gt;
    2   #include &lt;sstream&gt;
    3   #include &lt;string&gt;
    4   
    5   using namespace std;
    6   
    7   void main(void)
    8   {
    9         string Source("These are the voyages....");
   10         char Dest[81] = "";
   11         istringstream InputStream(Source);
   12         ostringstream Buffer;
   13         if(!InputStream){
   14              cerr &lt;&lt; "Error Setting up stream";
   15         }
   16         InputStream.get(Dest,81,'e');
   17         Buffer &lt;&lt; Dest &lt;&lt; endl;
   18         InputStream.seekg(0,ios_base::beg);
   19         InputStream.get(Dest,InputStream.rdbuf()-&gt;in_avail(),'\n');
   20         Buffer &lt;&lt; Dest &lt;&lt; endl;
   21         InputStream.seekg(0,ios_base::beg);
   22         InputStream.get(Dest,5,'\n');
   23         Buffer &lt;&lt; Dest &lt;&lt; endl;
   24         cout &lt;&lt; Buffer.str() &lt;&lt; endl;
   25   }


</pre>

</body>
</html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -