C++ STL 总结
来源:互联网 发布:算法导论 豆瓣 编辑:程序博客网 时间:2024/06/05 19:50
资料地址:http://blog.chinaunix.net/uid-24219701-id-2181266.html
一、简介
STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称。
STL的代码从广义上讲分为三类:algorithm(算法)、container(容器)和iterator(迭代器)。
容器:是可容纳一些数据的模板类;
算法:就是处理容器里面数据的方法、操作;
迭代器:遍历容器中数据的对象(它将算法和容器连在一起)。
二、容器实例
1)list,vector,deque- - 队列容器;
2)set,multisets,map,multimaps - - 关联容器;
1. 向量(vector)
1)初始化实例
<span style="font-size:14px;">//vector初始化实例#include "stdafx.h"#include <iostream>#include <vector>using namespace std;int ar[10] = {12, 45, 234, 64, 12, 35, 63, 23, 12, 55};char* str = "Hello World";int _tmain(int argc, _TCHAR* argv[]){vector<int> vec1(ar, ar+10);vector<char> vec2(str, str+strlen(str));cout << "vec1:";for (vector<int>::const_iterator p1 = vec1.begin(); p1 != vec1.end(); ++p1)cout << *p1; //&表示取地址,是取地址;//*是指针,是取地址的内容;cout << '\n' << "vec2:";for (vector<char>::const_iterator p2 = vec2.begin(); p2 != vec2.end(); ++p2)cout << *p2;cout << '\n';system("PAUSE");return 0;}</span>
2)操作实例
//vector操作实例#include "stdafx.h"#include <iostream>#include <vector>using namespace std;int _tmain(int argc, _TCHAR* argv[]){vector<int> vec1;vector<int> vec2(10, 6);vector<int> vec3(vec2.begin(), vec2.begin() + 3);vector<int>::iterator i;//按顺序显示vec1cout << "vec1.begin() ~ vec1.end():"<<'\n';for (i = vec1.begin(); i != vec1.end(); ++i)cout << *i << " ";cout << endl;vec1.push_back(2); //在最后添加一成员vec1.push_back(4);vec1.insert(vec1.begin()+1, 5);//在vector第1+1个位置上插入"5"vec1.insert(vec1.begin()+1, vec3.begin(), vec3.end());cout << "after push and insert,vec1 is :"<<'\n';for (i = vec1.begin(); i != vec1.end(); ++i)cout << *i << " ";cout << endl;vec2.assign(8, 1); //重新给vec2赋值,8个成员初始值都为1(全部重新赋值)cout << "vec2.assign(8,1) is :" << '\n';for (i = vec2.begin(); i != vec2.end(); ++i)cout << *i << " ";cout << endl;cout << "vec1.front() is :" << vec1.front() << endl;cout << "vec1.back() is :" << vec1.back() << endl;cout << "vec1.at(4) is :" << vec1.at(4) << endl; //和数组类似,实际是第5个cout << "vec1[4] is:" << vec1[4] << endl;vec1.pop_back();vec1.erase(vec1.begin()+1, vec1.end()-2);cout << "after pop and erase(vec1.begin()+1, vec1.end()-2),vec1 is :" << '\n';for (i = vec1.begin(); i != vec1.end(); ++i)cout << *i << " ";cout << endl;//vec1.size();//vec1.empty();system("PAUSE");return 0;}
待续。。
0 0
- c++STL总结
- C++STL一般总结
- 【C++】STL容器的总结
- C++STL之list用法总结
- C++STL库函数之string用法总结
- c++STL(六)各种函数总结
- 【c++】STL里的priority_queue用法总结
- C++STL之string的用法总结
- C++:STL常用函数模块总结(vector)
- C++:STL常用函数模块总结(set)
- C++:STL常用模块总结(map)
- 【STL】STL 一般总结
- STL总结
- STL 总结
- STL 总结
- stl总结
- stl总结
- STL总结
- 我所熟悉的C++智能指针auto_ptr vs shared_ptr (一)
- PHPExcel导出表格
- 浅析Java中CountDownLatch用法
- 用Memcache解决数据库高并发访问的瓶颈问题
- 关于reset.css的疑问:为什么一定要重置浏览器样式?
- C++ STL 总结
- Clojure语言十四 常用宏
- Github上的andoird开源组件整理
- android主线程访问网络的方法
- UWP开发:自定义Behavior的使用
- leetcode 274 : H-Index
- Linux 系统添加环境变量
- Android高效加载大图、多图解决方案,有效避免程序OOM
- Android AIDL IPC机制