STL(Standard Template Library)
STL is a c plus software library that influenced many parts of the C++ Standard Library.It provides four components, which called algorithms, containers, functors, and iterators. Such as HP STL、PJ STL、 SGI STL etc.
STL has been built within your complier.And it has many different versions.http://write.blog.youkuaiyun.com/postedit
In ANSI C ++ STL is organized into 13 header files:<algorithm>, <deque>, <functional><iterator>, <vector>, <list>, <map>, <memory>, <numeric>, <queue>, <set>, <stack>, <utility>.
And STL can be devided into 6 parts, including containers, iterators, allocators, adaptors, algorithms, functors.
Vector
Vector is considered a container, because of it can storge variable types objects just like containers.it can be used as a dynamic array . In order to use vector, we should include the header file <vector>. And the vector is contained in the std namesapce,so if we intend to use the vector, we also need to limit the namespace as follows:
usingnamespace std;
Of course,for using vector, there are some advantages but also some disadvantages.It can work fast for random access..., while slowly for insertion and deletion...
Constructors:
vector();
vector(int initialcapacity, int capacityIncrement);
vector(int initialcapacity);
For the first constructor, operator will manage the vector automatically.but for the latter two constructors, vector will be initialized with the fixed capacity. and when the capacity is not enough to store the data, the vector' capasity will be increased with the size of capacityincrement.
define:
vector<type> vector_name;
member functions:
assign(beg, end);
assign the data of the region between beg and end to c.
assgin(n, elem);
assigin n datas to c.
at(idx);
return the data of index idx,if cross the border, throw an exception :out_of_range.
back();
return the last data without check if the data exist.
begin();
return the firt address of the iterator.
capacity();
return the number of the datas that be stored in capacity.
clear();
remove all datas from the capacity.
empty();
check if the capacity is empty.
end();
refer to the next of the last data, which is not exist.
erase(pos);
delete the data at position pos,and return the address of the next data.
erase(beg, end);
delete datas of the region between beg and end, and return the address of the next data.
front();
return the first data.
get_allocator();
use the copy constructor and return a copy.
insert(pos, elem);
insert an element at the position pos, and return the address of the new data.
insert(pos, n, elem);
insert n datas at the position, and without return value.
max_size();
return the number of the maximum datas.
pop_back();
delete the last data.
push_back(elem);
insert an element to the end of the datas.
rbegin();
return the first data of an reverse queue.
rend();
refer to the next address of the last data in an reverse queue.
resize(num);
resize the length of the queue.
reserve();
reserve some capacitys.
size();
return the number of the datas in capacity.