STL: Standard C ++ Library
(1) Use of the string type STD: String
Include header file:
# Include <string>
Using namespace STD;
Usage:
STD: String S1;
STD: String S3 (S2 );
STD: String S2 ("this is a string ");
Get the iterator pointing to the beginning of the string
End obtains the iterator pointing to the end of the string.
Rbegin obtains the iterator pointing to the beginning of the reverse string.
Rend to get the iterator pointing to the end of the reverse string
Returns the size of the string.
The length () and size functions are the same.
Max_size the maximum possible size of a string
Possible size of the string without allocating memory again
Empty determines whether it is null
OPERATOR [] obtains the nth element, which is equivalent to an array.
C_str: returns the C-style const char * string.
Data obtains the string content address
Operator = value assignment operator
Reserve reserved space
Swap Functions
Insert characters
Append characters
Push_back append characters
Erase
Clear all content in the character container
Resize re-allocates Space
Assign is the same as the value assignment operator.
Replace substitution
Copy string to Space
Find, returns an index number based on 0
Rfind Reverse Lookup
Find_first_of finds any character in the substring and returns the first position.
Find_first_not_of searches for any character that does not contain a substring and returns the first position.
Find_last_of finds any character in the substring and returns the last position.
Find_last_not_of searches for any character that does not contain a substring and returns the last position.
Substr (N1, Len) returns a substring whose length starts from N1 and is Len.
Comparison string (all Relational operators supported)
Compare comparison string
Operator + String Link
Operator ++ = Operator
Operator = judge whether it is equal
Operator! = Judge whether it is not equal
Operator
Read a string from the input stream
Operator
Getline reads a row from the input stream
(2) Vector class template STD: vector member function
Include header file:
# Include <vector>
Using namespace STD;
Usage:
1> Initialization
STD: vector name;
STD: vector name (size );
STD: vector name (size, value );
STD: vector name (myvector );
STD: vector name (first, last );
2> Use
Assign (first, last) replaces the vector element with the element specified by the iterator first and last.
Assign (Num, Val) replaces vector elements with the num copy of Val
At (n) is equivalent to the [] Operator and returns the element of position N in the vector.
Front () returns the reference of the first element in the vector
Back () returns the reference of the last element in the vector.
Begin () returns the iterator of the first element in the vector.
End () returns the iterator of the last element in the vector.
Max_size () maximum return vector capacity (maximum number of elements that a vector can accommodate)
Capacity () returns the maximum number of elements that a vector can hold currently.
Clear () deletes all elements in a vector.
Empty () returns true if the vector is null
Erase (START, end) deletes elements within the specified range of the iterator start end.
Erase (I) deletes the element pointed to by iterator I
Insert (I, x) inserts X into the position specified by iterator I.
Insert (I, n, x) inserts n copies of X into the position specified by iterator I.
Insert (I, start, end) inserts values in the range specified by the iterator start and end into the position specified by the iterator I
Push_back (x) inserts X into the end of the Vector
Pop_back () deletes the last element in the vector.
Rbegin () returns a reverse iterator that points to an element that crosses the last element in the vector.
Rend () returns a reverse iterator pointing to the first element in the vector.
Reverse () reverse element order
Resize (n, x) changes the vector size to N, and the initial value of the new element is assigned to X.
Size () returns the vector size.
Swap (vectorref) exchanges the content of two vectors
(3) Double-end queue template STD: deque member function:
Include header file:
# Include <deque>
STD: deque name;
Usage:
STD: deque name (size );
STD: deque name (size, value );
STD: deque name (mydeque );
STD: deque name (first, last );
Most of its member functions are the same as STD: vector.
PS:
Push_front (x) puts X in the header of the bidirectional queue
Pop_front () deletes the first element of the two-way queue
(4) linked list template STD: List member function:
Header file:
# Include <list>
Using namespace STD;
Usage:
STD: List name;
STD: List name (size );
STD: List name (size, value );
STD: List name (mylist );
STD: List name (first, last );
Most of its member functions are the same as STD: vector.
PS:
Push_front (x) puts X in the head of the linked list
Pop_front () deletes the first element of the linked list
Merge (listref) inserts all elements in the linked list referenced by listref into the linked list.
Remove (VAL) removes all elements whose values are Val from the linked list.
Remove_if (Pred) deletes the pred in the linked list as the true element.
(Predicates are the descriptions of element storage and retrieval, such as STD: less, STD: greater. Then they are arranged in descending/ascending order. You can also define your own predicates)
Sort () sorts linked lists based on default predicates
Sort (Pred) sorts linked lists based on given predicates
Unique () deletes all repeated elements so that the linked list does not contain repeated elements.
Unique (Pred) deletes all repeated elements based on the PRED Pred, so that there are no repeated elements in the linked list.
Note: vector and deque support random access, while list does not support random access, so [] access is not supported!
(5) Container adapter Stack class STD: Stack member function
Header file:
# Include <stack>
Using namespace STD;
Usage:
Stack implements advanced and later operations
STD: stack name;
Type is the data type of the stack operation.
The container is the container type used to implement the stack. It can be STD: vector, STD: deque, STD: List
For example
STD: Stack intstack;
Only empty (), size (), top (), push (), pop ()
(6) Container adapter queue class STD: queue member function:
Header file:
# Include <queue>
Using namespace STD;
Usage:
Queue for first-in-first-out operations
STD: queue name;
Type is the data type of queue operations.
Container is the container type used to implement the queue. It can be STD: vector, STD: deque, STD: List
Only empty (), size (), Front (), back (), push (), pop ()
(7) associated containers:
Collection class STD: Set
Multiple collection classes STD: Multiset
STD ing Class STD: Map
Multi- ing STD: multimap
Bit Set STD: bitset
(8) general algorithms (applicable to the above STL)
Header file:
# Include <algorithm>
Using namespace STD;
Function:
1. Non-correction Sequence Algorithm:
2. Sequence Correction Algorithm:
3. Sorting Algorithm:
4. Numerical Algorithm:
(9) iterator (similar to the pointer function, access the container content)
For example:
STD: vector intvector;
STD: vector: iterator first = intvector. Begin ();
// Begin () gets the iterator pointing to the beginning of the vector. * first gets the value of the first element.
STD: vector: iterator last = intvector. End ();
// End () gets the iterator pointing to the end of the vector. * The last element is obtained.