Container
来源:互联网 发布:淘宝手表代购哪家靠谱 编辑:程序博客网 时间:2024/04/28 00:06
vector
(constructor)
#include<vector>std::vector<int> first; // empty vector of intsstd::vector<int> second (4,100); // four ints with value 100std::vector<int> third (second.begin(),second.end()); // iterating through secondstd::vector<int> fourth (third); // a copy of third
Iterators:
std::vector<int>::iterator it = myvector.begin()
Capacity:
std::cout << "0. size: " << myints.size() << '\n';myvector.resize(8,100);while (!myvector.empty());
Element access:
myvector.front() -= myvector.back();
Modifiers:
myvector.assign(7,100);myvector.push_back(myint);myvector.pop_back();it = myvector.begin();myvector.insert(it+2,anothervector.begin(),anothervector.end());myvector.insert(it,2,300);myvector.insert(it,300);myvector.erase(myvector.begin(),myvector.begin()+3);myvector.swap(anothervector);myvector.clear();
queue
(constructor)
#include <queue> std::deque<int> mydeck (3,100); // deque with 3 elementsstd::queue<int> first; // empty queuestd::queue<int> second (mydeck);
while (!myqueue.empty());std::cout << "0. size: " << myints.size() << '\n';myqueue.front() -= myqueue.back();myqueue.push (myint);myqueue.pop();
stack
(constructor)
#include <stack> std::deque<int> mydeck (3,100); // deque with 3 elementsstd::stack<int> first; // empty stackstd::stack<int> second (mydeque);
std::cout << "0. size: " << myints.size() << '\n';mystack.push(myint);while (!mystack.empty()){ std::cout << ' ' << mystack.top(); mystack.pop();}
set
(constructor)
#include <set>std::set<int> first; // empty set of intsint myints[]= {10,20,30,40,50};std::set<int> second (myints,myints+5); // rangestd::set<int> third (second); // a copy of secondstd::set<int> fourth (second.begin(), second.end()); // iterator ctor.
Iterators:
std::set<int>::iterator it=myset.begin();
Capacity:
while (!myset.empty());std::cout << "1. size: " << myints.size() << '\n';
Modifiers:
myset.clear();myset.insert (1101);std::set<int>::iterator it = myset.begin();myset.erase (it);myset.erase (40);
Operations:
myset.erase (myset.find(40));if (myset.count(i)!=0) std::cout << " is an element of myset.\n";std::set<int>::iterator itlow,itup;itlow=myset.lower_bound (30);itup=myset.upper_bound (60); std::pair<std::set<int>::const_iterator,std::set<int>::const_iterator> ret;ret = myset.equal_range(30);std::cout << "the lower bound points to: " << *ret.first << '\n';std::cout << "the upper bound points to: " << *ret.second << '\n';
map
(constructor)
#include <map>std::map<char,int> first;first['a']=10;struct classcomp { bool operator() (const char& lhs, const char& rhs) const {return lhs<rhs;}};std::map<char,int,classcomp> fourth;
Iterators:
for (std::map<char,int>::iterator it=mymap.begin(); it!=mymap.end(); ++it) std::cout << it->first << " => " << it->second << '\n';
Capacity:
while (!mymap.empty()){ std::cout << mymap.begin()->first << " => " << mymap.begin()->second << '\n'; mymap.erase(mymap.begin());}std::cout << "mymap.size() is " << mymap.size() << '\n';
Modifiers:
mymap.clear();mymap.insert ( std::pair<char,int>('a',100) );mymap.erase('c');
Operations:
std::cout << "a => " << mymap.find('a')->second << '\n';if (mymap.count('c')>0) std::cout << " is an element of mymap.\n";itlow=mymap.lower_bound ('b'); // itlow points to bitup=mymap.upper_bound ('d'); // itup points to e (not d!)mymap.erase(itlow,itup);
0 0
- Container
- Container
- Container
- Container
- Container
- Container move to Container
- vector container
- 中的Container
- Container 总结
- MKV container
- FLV container
- Tomcat Container
- vector container
- string container
- Codec & Container
- STL Container
- key container
- tomcat7--container
- WPF drag过程中显示ToolTip.
- CSS水平垂直居中的几种方法
- Groovy入门教程
- 联系人名称排序
- 设计模式(值对象)
- Container
- Odoo 主题介绍
- 浅谈插入排序
- OkHttpUtils请求网络查询手机号码归属地
- android性能优化
- linux命令
- SparkSQL UDF使用方法与原理详解
- bash 统计文件行数
- Ajax重构