使用STL的理由:
/+
* Reasons to use C++ standard library :
* 1. Code reuse, no need to re- invent the wheel.
* 2. Efficiency (fast and use less resources)。Modern C++ compiler are usually tuned to optimize for C++ s tandard library code .
* 3. Accurate, less buggy .
* 4. Terse, readable code; reduced control f1ow .
* 5. Standardization, guarenteed availability
* 6. A role model of writing library .
* 7. Good knowledge of data structures and algori thms .
*/
概述
STL全称为Standard Templates Library,即标准模板库,它是C++标准库的一个子集,主要包含三大部分:
Containers (容器)和Algorithms(算法)以及 Iterators(迭代器);
迭代器的出现是为了让两者更好地结合,
下面我们来看一个简单的STL示例:
示例:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
//Container:vector
vector&l