First article: STL Introduction

Source: Internet
Author: User

Written in front of the words: in the Internet to find a lot of do not find the right STL data, helpless can only see English, but the English level is really too rubbing, translation down oneself feel embarrassed, so hang up let everybody correct, hope many criticisms!


Introduction to the Standard Template Library (STL)

  The standard Template Library, or STL, is a C + + container class library, algorithm, and iterator that provides a number of basic algorithms and data structures for computer science.
STL is a general library, meaning that its components are strongly parameterized, and almost every STL component is a template. You should use STL in your
Understand how a template works in C + + before.

Containers and algorithms

  Like many class libraries, STL includes container classes, which are intended to include other objects. STL includes Vector,list,deque,set,multiset,

Map, Multimap, Hash_set, Hash_multiset, Hash_map, and Hash_multimap classes. Each of these classes is a template,
and can be instantiated as any type that contains an object. For example, you can use vector<int> to implement many of your ways of using C-language arrays, except
Vector eliminates the task of manually managing dynamic memory allocations.

 1  vector<int  > V (3 ); //  declares a container with three elements  2  v[0 ] =  ;  3  v[1 ] = v[ 0 ] + ;  4  v[2 ] = v[          0 ] + v[1 ]; //  v[0] = = 7, v[1] = =, v[2] = =  

The STL also includes a large set of algorithms that manipulate the data stored in the container. You can reverse the order of elements in the vector, for example, by using the reverse algorithm

// v[0] = =, v[1] = = Ten, v[2] = = 7 

  There are two points to note about the reverse call. First, it is a global function, not a member function; second, it takes two arguments instead of a
; It operates a series of elements, not a container. In this particular case, these changes apply to all containers.

The situation that causes these facts is the same: reverse, like other STL algorithms, is separated from the STL container class. This means that reverse not only reverses the order of the elements in the container, but also applies to the elements in the list, and even applies to the elements of the array in C.
The following procedures are also valid

1     Doublea[6] = {1.2,1.3,1.4,1.5,1.6,1.7 };2Reverse (A, A +6);3       for(inti =0; I <6; ++i)4cout <<"a["<< I <<"] = "<< A[i];

This example uses a range, like an example of reversing a vector: reversing the first parameter is the beginning of the range, and the second argument points to the next of the last element. The range represents [A,a+6]; an asymmetric symbol is a hint that two endpoints are different, that is, first the beginning of the range and the second argument pointing to the next of the last element.

  Iterator, not finished, to be continued ...

First article: STL Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.