📄 iterators.html
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>cppreference</title>
</head>
<body>
<table width="100%" bgColor="#eeeeff">
<tbody>
<tr>
<td><a href="http://64.4.48.250/cgi-bin/index.html">cppreference.com</a>
-> C++ Iterators(迭代器)</td>
</tr>
</tbody>
</table>
<h3>C++ Iterators(迭代器)</h3>
<p>迭代器可被用来访问一个容器类的所包函的全部元素,其行为像一个指针。举一个例子,你可用一个迭代器来实现对vector容器中所含元素的遍历。有这么几种迭代器如下:</p>
<table width="75%" align="center">
<tbody>
<tr>
<th>迭代器</th>
<th>描述</th>
</tr>
<tr bgColor="#eeeeff">
<td>input_iterator</td>
<td>提供读功能的向前移动迭代器,它们可被进行增加(++),比较与解引用(*)。</td>
</tr>
<tr>
<td>output_iterator</td>
<td>提供写功能的向前移动迭代器,它们可被进行增加(++),比较与解引用(*)。</td>
</tr>
<tr bgColor="#eeeeff">
<td>forward_iterator</td>
<td>可向前移动的,同时具有读写功能的迭代器。同时具有input和output迭代器的功能,并可对迭代器的值进行储存。</td>
</tr>
<tr>
<td>bidirectional_iterator</td>
<td>双向迭代器,同时提供读写功能,同forward迭代器,但可用来进行增加(++)或减少(--)操作。
</TD< TR>
<tr bgColor="#eeeeff">
<td>random_iterator</td>
<td>随机迭代器,提供随机读写功能.是功能最强大的迭代器,
具有双向迭代器的全部功能,同时实现指针般的算术与比较运算。</td>
</tr>
<tr>
<td>reverse_iterator</td>
<td>如同随机迭代器或双向迭代器,但其移动是反向的。(Either
a random iterator or a bidirectional iterator that moves in reverse
direction.)(我不太理解它的行为)</td>
</tr>
</tbody>
</table>
<p>第种容器类都联系于一种类型的迭代器。第个STL算法的实现使用某一类型的迭代器。举个例子,vector容器类就有一个<b>random-access</b>随机迭代器,这也意味着其可以使用随机读写的算法。既然随机迭代器具有全部其它迭代器的特性,这也就是说为其它迭代器设计的算法也可被用在vector容器上。</p>
<p>如下代码对vector容器对象生成和使用了迭代器:</p>
<pre> vector<int> the_vector;
vector<int>::iterator the_iterator;
for( int i=0; i < 10; i++ )
the_vector.push_back(i);
int total = 0;
the_iterator = the_vector.begin();
while( the_iterator != the_vector.end() ) {
total += *the_iterator;
the_iterator++;
}
cout << "Total=" << total << endl;
</pre>
提示:通过对一个迭代器的解引用操作(*),可以访问到容器所包含的元素。
</body>
</html>
<br><html>
<head>
<meta http-equiv='Content-Type' content='text/html' charset='ISO_8859_1'>
<title>235</title>
<style>
<!--
div#StrBanner /* Creates Nonscrolling banner region */
{
position: relative;
left: 0px;
padding: 0px 0px 0px 0px;
border-bottom: 1px solid #999999;
background-color: #99ccff;
}
div#titlerow /* <!-- 235 --> */
{
padding: 0px 10px 0px 22px;
}
h1, h2, h3, h4 /* <!-- 235 --> */
{
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-bottom: .4em;
margin-top: 0em;
font-weight: bold;
}
-->
</style>
</head>
<body><!-- 235 -->
<div id='StrBanner'>
<div>
<table class='TableBanner' cellspacing='0'>
<tr>
<td ALIGN=RIGHT><!-- 235 --></td>
<td ALIGN=RIGHT><!-- 235 --></td> </tr>
</table>
</div>
<div id='TitleRow'>
<h3>Extr<!-- 235 -->acted by <!-- 235 -->Tria<!-- 235 -->l version of Ch<!-- 235 -->mDecom<!-- 235 -->piler<!-- 235 --> (<a href="http://www.etextwizard.com/download/cd/cdsetup.exe" target=_blank>Download Now</a>).</h3>
<h4>Once reg<!-- 235 -->istered, <!-- 235 -->all restrictions of the Tr<!-- 235 -->ial version are removed.</h4>
<a href="http://www.zipghost.com/order_chmdecompiler.html" target=_blank><H3>B<!-- 235 -->uy Now</H3></a>
</div>
</div>
<p><!-- 235 -->
</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -