Common STL://vector: Dynamic array, header file #include <vector>//definition:vector<type> vec_name;//definition shaping vectorvector<int> a;// Add elements dynamically to the end of the container a.push_back (1); A.push_back (2);//Returns the number of elements int n = a.size ();//traversal container for (int i=0; i<n; i++) {Cout<<a[i] <<endl;} A.clear ();//string: String container header file # include <string>//definition string str, STR1 = "CD";//Add character element Str.push_back (' a ') to the end; char C = ' b '; str + = c;str + = str1;//output with traversal cout<<str<<endl;int n = str.size (); for (int i=0; i<n; i++) {cout<<str[ I]<<endl;} Sub returns a substring of STR with a starting position of Str[_off], _countstring sub = str.substr (_off, _count), Str.clear (); Queue: Header file #include <queue>//queue<type> Q; Queue<int> Q; Q.push (1); Q.push (2); int n = q.size (); while (Q.size () > 0) {cout<<q.front (); Q.pop (); }//stack: Stack header file #include <stack>stack<int> s:s.push (1); S.push (2); while (! S.empty ()) {cout<<s.top () <<endl;; S.pop ();} Set: Set header file #include <set>set<int> S; S.inserT (1); S.insert (2); S.erase (1); int _count = S.count (2); S.clear ();//map: Key-Value Mapping container header file: #include <map>map<int, int> M; M[1] = 1; M[2] = 2;cout<<m[1]<< ' <<M[2]<<endl; M.clear (); Library functions: Common libraries: #include <algorithm> #include <cstdlib> #include <math.h> common functions: Sorting functions sort://int A [100]; Vector<int> Vec;sort (A, a+100); sort (Vec.begin (), Vec.end ()), binary lookup function://vector<int> vec//take int container as an example, The IDX returns the subscript of the first element greater than or equal to X in VEC//idx2 returns the subscript of the first greater than x element in VEC, an int idx = Lower_bound (Vec.begin (), Vec.end (), X)-Vec.begin (); int idx2 = Upper_bound (Vec.begin (), Vec.end (), X)-Vec.begin (); Mathematical function: Pow: power function sqrt: square root function ABS: Absolute value function fabs: floating-point absolute value function
2016/05/06