標準模板庫(STL)學習指南之List容器
1
#include <list>
2
#include <string>
3
#include <iostream.h>
4
#include <algorithm> //for_each()
5
6
using namespace std;
7
8
9
void PrintIt(string &strPrint)
10
{
11
cout<<strPrint<<endl;
12
}
13
14
int _tmain(int argc, _TCHAR* argv[])
15

{
16
list<string> aa;
17
char a;
18
19
aa.push_back("aaaaaaa");
20
aa.push_back("ccccccc");
21
cout<<aa.size()<<endl;
22
23
list<string>::iterator aaiterator;
24
25
for(aaiterator=aa.begin();aaiterator!=aa.end();aaiterator++)
26
{
27
cout<<*aaiterator<<endl;
28
}
29
cin>>a;
30
31
32
cout<<"方法二:"<<endl;
33
for_each(aa.begin(),aa.end(),PrintIt);
34
35
return 0;
36
}
37
38
39
40

2

3

4

5

6

7

8

9

10



11

12

13

14

15



16

17

18

19

20

21

22

23

24

25

26



27

28

29

30

31

32

33

34

35

36

37

38

39

40

posted on 2007-08-02 17:43 飛天 閱讀(331) 評論(0) 編輯 收藏 引用 所屬分類: C/C++