use_iter.cpp

来自「《C/C++程序员实用大全》配套代码,适用初学C++的人员。」· C++ 代码 · 共 35 行

CPP
35
字号
//  If you use Visual C++, set the compile options to /GX

#ifdef __BCPLUSPLUS__
#include <iostream.h>
#include <list.h>
#else
#include <iostream>
#include <list>
#endif

using namespace std;
typedef list<int> LISTINT;

void main(void)
 {
   LISTINT listOne;
   LISTINT::iterator i;

   // Add some data
   listOne.push_front (2);
   listOne.push_front (1);
   listOne.push_back (3);

   // 1 2 3
   for (i = listOne.begin(); i != listOne.end(); ++i)
     cout << *i << " ";
   cout << endl;

   // 1 1 1 1
   for (i = listOne.end(); i != listOne.begin(); --i)
     cout << *i << " ";
   cout << endl;

 }

⌨️ 快捷键说明

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