📄 isstream.htm
字号:
<html>
<head>
<title> The basic_istringstream (istringstream) Class</title>
</head>
<body bgcolor="#FFFFFF">
<img src="iststban.gif">
<pre>
<font size=5>Class Name</font> basic_istringstream
<font size=5>Header File</font> <sstream>
<font size=5>Classification</font> Input/Output (Format Class)
</pre>
<a href="isstream.htm#diagram">Class Relationship Diagram</a><br>
<br>
<a href="isstream.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>
<a href="strbuf.htm">basic_stringbuf</a>
<h1>Methods</h1>
<pre>
<a href="isstream.htm#istring1">explicit basic_istringstream(ios_base::openmode OMode = ios_base::in)</a><br>
<a href="isstream.htm#istring2">explicit basic_istringstream(const basic_string<charT,traits,Allocator>& Str,ios_base::openmode OMode = ios_base::in)</a><br>
<a href="isstream.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="isstream.htm#example"><h2>Example</h2></a><br
<hr>
<a name="desc"><h3>Class Description</h3></a>
<p>
The basic_istringstream class implements the functionality of an object oriented input memory device.
Whereas the cin type <i>basic_istream</i> object is normally tied to the console, and the <i>ifstream</i>
class is connected to a file, or a device that is recognized as a file. The basic_istringstream
class is connected to a block of memory, or a character array. The basic_istringstream
class is a model of a character, or byte array. The istringstream class is derived from the
basic_istream class. The standard typedef for basic_istringstream is <i>istringstream</i>.
</p>
<p>
Whereas the basic_istream class has a basic_streambuf component, and the ifstream has a filebuf
component, the istringstream 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 istringstream memory device
through the stringbuf component. The stringbuf component can be reached by the rdbuf() member
function.
</p>
<hr>
<pre>
<a name="istring1">Method basic_istringstream()</a>
Access Public
Classification Constructor
Syntax explicit basic_istringstream(ios_base::openmode OMode = ios_base::in)
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
in open for reading
trunc erase buffer start at 0
________________________________________
Return None
</pre>
<hr>
<pre>
<a name="istring2">Method basic_istringstream()</a>
Access Public
Classification Constructor
Syntax explicit basic_istringstream(const basic_string<charT,traits,Allocator>& Str,ios_base::openmode OMode = ios_base::in)
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
in open for reading
trunc erase buffer start at 0
________________________________________
Str is a reference to a character buffer that will be used as the get area for the
istringstream object.
Return None
</pre>
<h3>Description</h3>
<p>
This basic_istringstream() method constructs a basic_istringstream object. It constructs a
stream that is uses Str as its buffer or get area.
</p>
<hr>
<pre>
<a name="rdbuf">Method rdbuf()</a>
Access Public
Classification Accessor
Syntax basic_filebuf<charT,traits>* 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_istringstream</h2></a>
<img src="istrgstr.gif">
</p>
<hr>
<a name="example"></a>
<img src="lego.gif">
<pre>
1 #include <iostream>
2 #include <sstream>
3 #include <string>
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 if(!InputStream){
13 cerr << "Error Setting up stream";
14 }
15 InputStream.get(Dest,81,'e');
16 cout << Dest << endl;
17 InputStream.seekg(0,ios_base::beg);
18 InputStream.get(Dest,InputStream.rdbuf()->in_avail(),'\n');
19 cout << Dest << endl;
20 InputStream.seekg(0,ios_base::beg);
21 InputStream.get(Dest,5,'\n');
22 cout << Dest << endl;
23 }
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -