string
#include <string>
#include <iostream>
using namespace std;
int main(){
string str="There are two needles in this haystack with needles.";
cout<<str<<endl;
int pos=str.find("needles");
cout<<pos<<endl;
cout<<str.find("needles",pos+1,6);
cout<<str.substr(3,5)<<endl;
cout<<str.substr(str.find("are"))<<endl;
string str2="tempstr";
str.append(str2);
str.append(str2,6,3);
str.append("dots are cool",5);
cout<<str[0]<<endl;
str.insert(6,str2);
str.insert(6,str2,3,4);
str.insert(10,str2,4);
str.insert(15,2,':');
str.erase (10,8);
str.erase(str.begin+9)
str.erase()
return 0;
}
vector
push_back(data)
pop_back()
at(idx)
begin()
end()
front()
back()
insert(pos,elem)
max_size()
capacity()
size()
resize(size)
reserve(size)
erase(pos)
erase(beg,end)
clear()
rbegin()
rend()
empty()
swap(vector)
#include <vector>
#include <iostream>
using namespace std;
int main(){
vector<int>test;
vector<int>::iterator it;
for(int i=1;i<10;i++){
test.push_back(i);
}
it= test.begin();
cout<<test.size()<<endl;
cout<<test.front()<<endl;
test.insert(it,10);
test.erase(test.begin(),test.begin()+2);
for (;it != test.end(); ++it)
cout << ' ' << *it;
if(test.empty()==true){
cout<<"empty";
}
else
cout<<"not empty"<<endl;
while(!test.empty()){
cout<<"out"<<test.back();
test.pop_back();
}
return 0;
}
map
begin() 返回指向map头部的迭代器
end() 返回指向map末尾的迭代器
for(auto it = map.begin(); it != map.end(); ++it)
clear() 删除所有元素
count() 返回指定元素出现的次数
empty() 如果map为空则返回true
equal_range() 返回特殊条目的迭代器对
erase() 删除一个元素
find() 查找一个元素
int found = map.find(findMe);返回索引
get_allocator() 返回map的配置器
insert() 插入元素
map.insert(std::make_pair(nums[i], i));
key_comp() 返回比较元素key的函数
lower_bound() 返回键值>=给定元素的第一个位置
max_size() 返回可以容纳的最大元素个数
rbegin() 返回一个指向map尾部的逆向迭代器
rend() 返回一个指向map头部的逆向迭代器
size() 返回map中元素的个数
swap() 交换两个map
upper_bound() 返回键值>给定元素的第一个位置
value_comp() 返回比较元素value的函数
set
#include<set>
#include<iostream>
using namespace std;
int main(){
set<int> myset;
set<int>::iterator it;
for(int i=0;i<10;i++){
myset.insert(i);
}
int myints[]={5,6,7};
myset.insert(myints,myints+3);
if(myset.count(5)==0){
cout<<"不存在";
}
else
cout<<"存在"<<endl;
myset.erase(5);
it=myset.begin();
it=myset.find(6);
myset.erase(it);
myset.erase(it,myset.end());
for(it=myset.begin();it!=myset.end();it++){
cout<<*it<<endl;
}
return 0;
}