1. Additional String operations
In addition to the common operation of most sequential containers in the preceding sequence, the string type provides a reciprocal conversion between a string and a C-style character array, and allows us to replace the iterator version with subscript.
string s (cp,n);//CP is an array, copy the first n, the arrays need to end with a null character, copied to the null character end string S (s2,pos2),//s2 is a string, the character from the Pos2 copy string S (s2,pos2,len2);
S.substr (m,n); take the M position of the s character to n position
There are other insert and erase versions of String, as well as two additional member functions append and replace
String search operations: 6 different search functions, 4 overloaded versions per function. Find (a), where//a first appears rfind (a);//Last occurrence. Find_first_of (a); the position of the first occurrence of any character in the//a
Find_last_of (a); Find_first_not_of (a); Find_last_not_of (a); The form of a c,pos s2,pos cp,pos cp,pos,n
String comparison function compare, similar to strcmp in a C-style string.
String converted to numeric string s2= "pi=3.14" D=stod (S2.substr (s2.find_first_of ("+-.0123456789"))
2. Container Adapter
Three sequential container adapters: Stack, queue, priority_queue. Containers, iterators, and functions all have adapters. To make it behave like a different type, function, or iterator, the adapter is equivalent to defining a new interface above the underlying sequential container type.
Define Adapter:stack<int> Stk (DEQ);//copy elements from DEQ to STK
All adapters require the container to have the ability to add, remove, and access tail elements. Stack (except array and forward_list), queue (List,deque), Priority_queue (Vector,deque)
Stack adapter: Stack. Stack default Deque implementation. The operation has S.pop ();//Deletes the top element of the stack and does not return the value. S.push (); S.emplace (); S.top ();//returns the top element of the stack, but does not eject the element
Queuing adapters: Queue and Priority_queue.queue are implemented by default based on Deque. Priority_queue is vector-based by default.
C + + sequential containers (3)