-
a pair class
:表达两个东西之间的关系 -
容器
-
vector
:可扩展的数字,在一头固定增长 -
deque
:可扩展的数字,往两头增长 -
list
:内部是双向链表 -
set
:集合,没有重复的,无序的 -
map
:映射(ket,value)
-
-
基本函数的模板(排序、搜索等)
以上所有的内容都在std
里(使用using namespace std;
)
所有标识符都是小写
#include<iostream>
#include<vector>
using namespace std;
int main(){
vector<int> x; //可以不用设置初始vector大小
for(int a=0;a<1000;a++)
x.push_back(a);
vector<int>::iterator p;
for(p=x.begin();p<x.end();p++)
cout<<*p<<" ";
return 0;
}
STL
:模板&重载
比较符号是比较两个vector
,而不是仅仅比较两个vector
里的内容
V.swap(v2)
是交换两个vector
,而不是仅仅交换两个vector
里的内容
V.at(index)
和V[index]
都可以访问对应索引的值
V.push_back(e)
:在V中存放e
V.pop_back()
:取出V中最后存入的数
v.insert(pos,e)
:在pos
处插入e
V.erase(pos)
:删掉pos
处的数
V.find(first,last,item)
:在first和last之间找出item,并且给出索引值
list
可以两边存放数值。
#include<iostream>
using namespace std;
#include<list>
#include<string>
int main(){
list<string> s;
s.push_back("Hello");
s.push_back("world");
s.push_front("tide");
s.push_front("cirmson");
s.push_front("alabama");
lis<string>::iterator p;
for(p=s.begin();p!=s.end();p++) //此处不可以使用p<s.end()
cout<<*p<<" ";
cout<<endl;
}
#include<map>
#include<string>
map<string,float> price;
price["snapple"]=0.75;
price["coke"]=0.50;
string item;
double total=0;
while(cin>>item)
total+=price[item];