This is a guide you how you are
Learn STL and practical articles under Microsoft Visual Studio. This article spoken from STL, step by step, gradually, involved in the method of STL writing code, STL code compilation, Namespace, ANSI / ISO string in STL, Various types In container, Template, Iterator, Algorithms, Allocator, container nested, etc., the author puts some suggestions in this article, and Point out the problem that should be noted when using STL. This article covers wide, and the perspective is comprehensive. It is not only suitable for beginners to learn STL, but also readers using STL.
Programming Practice Guide.
STL introduction
STL (Standard Template Library, Standard Template Library) is the current C today
Programmed people need a good technology. I think everyone who first school STL should spend some time to familiarize it. For example, there will be a lot of learning curves in a sharp rise, and some name is not easy to remember, maybe I know. The name has been used in light), however, if you have a STL, you will not feel headache. STL is more complex and powerful than MFC.
STL has some advantages:
You can easily achieve a series of algorithms such as search data or sort data sorting;
More secure and convenient when debugging procedures;
Even people who use STL in the UNIX platform you can easily understand (because STL is cross-platform).
background knowledge
Write this part is to let some beginner's readers have a good start in the challenging computer science field, not to understand the endless japanese terms and dull rules, just regarding those jars and rules here. STLER is used for self-entertainment creation.
Use code
The code used in this article is mainly guided in STL practice.
Some definitions of foundation concepts
Template - macro (Macro) of a class (and various data types and functions such as structures). Sometimes called a cookie cutter, a regular name should be called a generic - a class template called the generic class, and a function of a function is naturally called a modest function ( Generic function.
STL - Standard Template Library, some of the intelligent people written some templates now have become part of the standard C language used by each person.
Container - template class that can accommodate some data. There are versors such as VECTOR, SET, MAP, MULTIMAP and DEQUE in STL.
Vector - Basic Array Template, which is a container.
Cursor (Iterator) - This is a strange thing, it is a pointer to point to the elements in the STL container, or to other elements.
Hello World Program I am willing to write my program in my gold: a Hello World program. This program transmits a string to a character vector and then displays one of the characters in the vector. The vector is like a garden that is growing, and half of all STL containers is based on the vector. If you have the program, you will almost master half the entire STL. // Program: Vector Demo One // Objective: To understand the vector // #include "stdafx.h" in the STL - If you use the precompiled header file, you contain the header of the header file #include
Push_back is a standard function that puts data into a Vector (vector) or Deque (two-end queue). INSERT is a similar function, however it can be used in all containers, but usage is more complicated. End () is actually taking the end of the end (the previous elements at the end of the container) so that the loop is correctly run - it returns the pointer to the most close-to-array boundary. Just like an array in a normal cycle, such as for (i = 0; i <6; i ) {ar [i] = i;} --ar [6] does not exist, this element does not reach this element in the loop. Therefore, there will be no problem in the cycle.