当心忘记编写错误处理程序

当心忘记编写错误处理程序,当心错误处理程序本身有误。

 1 #include <iostream>
 2 #include <list>
 3 #include <numeric>
 4 
 5 using namespace std;
 6 //创建一个list容器的实例LISTINT,其存放int型数据
 7 typedef list<int> LISTINT;
 8 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 9 
10 int main(int argc, char** argv) {
11        //用LISTINT创建一个名为listOne的list对象
12     LISTINT listOne;
13     //指定i为迭代器变量
14     LISTINT::iterator i;
15     LISTINT::reverse_iterator ir;
16 
17     //从前面向listOne容器中添加数据
18     listOne.push_front (2);
19     listOne.push_front (1);
20 
21     //从后面向listOne容器中添加数据
22     listOne.push_back (3);
23     listOne.push_back (4);
24 
25     //从前向后显示listOne中的数据
26     for (i = listOne.begin(); i != listOne.end(); ++i)
27         cout << *i << " ";
28     cout << endl;
29 
30     //从后向后显示listOne中的数据
31     for (ir =listOne.rbegin();ir!=listOne.rend(); ++ir) 
32         cout << *ir << " ";
33     cout << endl;
34 
35     //从键盘上输入数据
36     for (i = listOne.begin(); i != listOne.end(); ++i) {
37         cout<<"listOne  :";
38         cin>>(*i);
39     }
40 
41     //从前向后显示listOne中的数据
42     for (i = listOne.begin(); i != listOne.end(); ++i)
43         cout << *i << " ";
44     cout << endl;
45     
46     //bidirectional迭代器不允许加减运算
47     // i=listOne.begin()+1;
48     return 0;
49 }

猜你喜欢

转载自www.cnblogs.com/borter/p/9417984.html