一.stl六大元件
1.容器:各種資料結構,如vector、list、deque、set、map等
2.演算法:各種常用的演算法,如sort、find、copy等
3.迭代器:容器與演算法間的膠合劑
4.仿函式:行為類似函式,可作為演算法的某種策略
5.介面卡:一種用來修飾容器或者仿函式或迭代器介面的東西
6.空間配置器:負責空間的配置與管理
二.vector存放內建資料型別
容器:vector
演算法:for_each
迭代器:vector::iterator
三.vector存放自定義資料型別#include
#include
#include
#include
#include
//標準演算法標頭檔案
using
namespace std;
void
myprint
(int val)
void
test01()
//第二種遍歷方式
for(vector<
int>
::iterator it = v.
begin()
; it != v.
end(
); it++
)//第三種方式,使用stl提供的演算法
for_each
(v.begin()
, v.
end(
), myprint);}
intmain()
四.容器巢狀容器#include
#include
#include
#include
#include
//標準演算法標頭檔案
using
namespace std;
class
person
string m_name;
int m_age;};
void
test01()
}void
test02()
}int
main()
#include
#include
#include
#include
//標準演算法標頭檔案
using
namespace std;
void
test01()
v.push_back
(v1)
; v.
push_back
(v2)
; v.
push_back
(v3)
; v.
push_back
(v4)
;for
(vectorint>>
::iterator it = v.
begin()
; it != v.
end(
); it++)}
}int
main()
C STL庫學習筆記(一) STL初識
容器 container 是一種資料結構,如list,vector,和deques 以模板類的方法提供。為了訪問容器中的資料,可以使用由容器類輸出的迭代器 迭代器 iterator 提供了訪問容器中物件的方法。例如,可以使用一對迭代器指定list或vector中的一定範圍的物件。迭代器就如同乙個指標...
C STL 學習筆記
一 stl a include include using namespace std 1 void sort iterator start,iterator end void sort iterator start,iterator end,strictweakordering cmp cmp 函...
C STL學習筆記
remove if使用方法 int a vectorarr a,a 14 std remove if arr.begin arr.end std bind2nd std less 100 for int i 0 i arr.size i 輸出結果為 240 100200 300102 555100 ...