C + + STL Library

Source: Internet
Author: User
Tags array length assert int size prototype definition strlen
#include <vector> detailed function implementation function: Vector<int> C. Initialization vector<vector that cannot be directly defined as a null two-dimensional vector <int> > Ivec (M,vector<int> (n,0));         M*n vector, all elements initialized to 0 vector<vector<int>> ret (m,vector<int> (n)),//m*n two-dimensional vector initialization c.clear ()
    Removes all data from the container.
    C.empty () Determines whether the container is empty.
    C.erase (POS) deletes data from the POS location c.erase (beg,end) deletes the data C.front () of the [beg,end) interval and returns the first data.
    C.insert (Pos,elem) Inserts a elem copy C.pop_back () at the POS location to delete the last data.
    C.push_back (elem) adds a data to the tail.
    C.resize (num) Reset the size of the container c.size () back to the number of actual data in the container. 
C.begin () returns the iterator that points to the first element of the container C.end () returns the iterator that points to the last element of the container C + + STL Stack header file is: #include <stack> Introduction to member functions of C + + STL Stack The operation comparison and allocation stack empty () The stack is empty returns the true Pop () remove the top element push () add element size () to the top of the stack () returns the number of elements in the stack the top () returns the topmost element bool 0 represents false 1 The basic operation of the true queue is: Team, as an example: Q.push (x);
Connect X to the end of the queue. Out of the team, as an example: Q.pop ();
The first element of the pop-up queue, note that the value of the pop-up element is not returned.
Access the first element of the team, as an example: Q.front (), the element that was first pressed into the queue.
Access the tail element of the team, as an example: Q.back (), the element that was last pressed into the queue. SentencedThe broken queue is empty, as in example: Q.empty (), returns True when the queue is empty.    Access the number of elements in the queue, for example: Q.size () string #include <string> the constructor of the string class: string (const char *s);     Initializes a string with the C string s (int n,char c);    The attribute description of the string is initialized with n character c: int capacity () const;    Returns the current capacity (that is, the number of elements in string that do not need to add memory) int max_size () const;        Returns the length int size () const of the maximum string that can be stored in a string object;       Returns the size of the current string int length () const;        Returns the length of the current string bool empty () const; Whether the current string is an empty void resize (int len,char c);//The current size of the string is set to Len, with character C padding the character of the Section string class: const char &operator[] (int n)
const;//a string of + + operations The const char &at (int n) const;//returns the character of the nth position of the string, noting that the position is a char &operator[starting from 0 (int n);
char &at (int n);
Assignment of String: string &operator= (const string &s);//Assign the string s to the current string, string &assign (const char *s);//Assign value with C-type string s String &assign (const char *s,int n);//////= n-word assignments Value string &assign (const string &s) starting with C string s;//assign string s to current string &assign (int n,char c);//Assign value to n character c to the current string &assign (const string &s,int start,int N); n characters that start from start in the string sAssign to the current string &assign (Const_iterator first,const_itertor last);//Assign a portion between the primary and last iterators to a connection string string: string            &operator+= (const string &s);//Connect the string s to the end of the current string &append (const char *s); Concatenate the C type string s to the end of the current string &append (const char *s,int n);//The first n characters of the C type string s are fonts to the end of the current string &append (const    String &s); With operator+= () string &append (const string &s,int pos,int N);//fonts to the end of the current string with n words from the pos in string S &        Append (int n,char c);
Add n characters C string &append (Const_iterator First,const_iterator last) at the end of the current string;//Connect the part between the iterator first and last to the end of the current string Comparison of string: bool operator== (const string &s1,const string &s2) const;//compares two strings for equality operator ">", "<", ">=", " <= ","!= "are overloaded for string comparisons; int compare (const string &s) const;//Compare current string and s size int compare (int pos, int n,const string &am P;s) const;//compares the current string of n characters starting at the POS with the size int compare (int pos, int n,const string &s,int pos2,int n2) const;// Compares the current string of n characters that start at the POS string strings string: string substR (int pos = 0,int n = NPOs) const;//Returns a string of n characters at the beginning of the POS, left-Right open string substr (int pos) const;//returns the exchange of substring string starting at the POS position: void    Swap (string &s2);  Swap the value of the current string with the S2 lookup function of the string class: int Find (char c, int pos = 0) const;//look for character C at the current string position int find (const char *s, int pos =  0 const;//start from POS find the position of the string s in the current string int find (const char *s, int pos, int n) const;//look up the position of the first n characters in the string s in the current string from the POS int found (const String &s, int pos = 0) const;//to start with POS find the string s position in the current string/find the location of success, failure returns the value of String::npos int rfind (char c, int pos = NP
OS) const;//the position of the character C in the current string from the beginning of the POS int rfind (const char *s, int pos = NPOs) const;
int rfind (const char *s, int pos, int n = npos) const;
int RFind (const string &s,int pos = NPOs) const; From the beginning of the POS to find the position of the first n characters in the string s in the current string, successfully return to the position, and return int find_first_of (char c, int pos = 0) const;//
Starting from Pos Find the first occurrence of the character c the position int find_first_of (const char *s, int pos = 0) const;
int find_first_of (const char *s, int pos, int n) const;
int find_first_of (const string &s,int pos = 0) const; From POSBegins to find the position of the character in the first n-character array of s in the current string.
Lookup failure Returns string::npos int find_first_not_of (char c, int pos = 0) const;
int find_first_not_of (const char *s, int pos = 0) const;
int find_first_not_of (const char *s, int pos,int n) const;
int find_first_not_of (const string &s,int pos = 0) const;
Finds the first occurrence of a character not in string s from the current string, and the failure returns STRING::NPOS int find_last_of (char c, int pos = NPOs) const;
int find_last_of (const char *s, int pos = NPOs) const;
int find_last_of (const char *s, int pos, int n = npos) const; 

int find_last_of (const string &s,int pos = NPOs) const;
int find_last_not_of (char c, int pos = NPOs) const;
int find_last_not_of (const char *s, int pos = NPOs) const;
int find_last_not_of (const char *s, int pos, int n) const;

int find_last_not_of (const string &s,int pos = NPOs) const; substitution function for string class: String &replace (int p0, int n0,const char *s)//delete p0 characters starting from N0, then insert string s string p0 at &replace (int p0, in T n0,const char *s, int n);//delete n0 characters from the P0 start, then insert the first n characters of string s in the p0 (int &replace, int N0,const string &s);//delete n0 characters starting from P0, then insert string s string p0 at &replace (int p0, int n0,const string &s, int pos, int n
//Delete the N0 character starting with P0, and then insert the N-character string &replace (int p0, int n0,int n, char c) in string s from Pos at P0, and then insert n characters at P0 String &replace (iterator first0, iterator last0,const char *s);//replace the portion between [first0,last0) with the string ' s string &replace ( Iterator First0, iterator last0,const char *s, int n);//replace the portion between [First0,last0] with the first n characters of S, String &replace (iterator First0, iterator Last0,const string &s)//Replace part of [First0,last0] with string s string &replace (iterator first0, iterator Last0,int N, char c);//replace the portion between [first0,last0] with n characters C string &replace (iterator first0, iterator Last0,const_iterator Const_iterator last);//Replace the part between [First0,last0] with the string between [First,last] Insert function of String class: String &insert (int p0,
const char *s);
String &insert (int p0, const char *s, int n);
String &insert (int p0,const string &s); String &insert (int p0,const string &s, int pos, intn); The first 4 functions insert the first n characters string &insert (int p0, int n, char c) at the beginning of the POS in the P0 position.//This function inserts n characters c iterator insert at P0 (iterator it, CH AR c)//inserts character C at it, returns the position of the inserted iterator, void Insert (iterator it, Const_iterator, Const_iterator last); last) character void insert (iterator it, int n, char c);//insert n character C String class delete function at it iterator erase (iterator first, iterator LA ST)//deletes all characters between [first,last), returns the position of the iterator after the deletion erase (iterator it);//Deletes the character that it points to, returns the location of the post-deletion iterator string &erase (int pos = 0, int n = npos);//delete the N-character at the beginning of the POS, return the modified string assert macro's prototype is defined in <assert.h> to terminate the program execution if its condition returns an error, the prototype definition: #include &
lt;assert.h> void assert (int expression);

The role of assert is to calculate the expression expression, if its value is false (that is, 0), then it first prints an error message to stderr, and then terminates the program by calling abort. Array length calculations: (1) sizeof method: sizeof (array name)/sizeof (array type name) Description: The array occupies bytes divided by the array type of bytes, resulting in the number of elements (2) strlen Description: strlen, To find the effective length of the string: strlen (character array name)//result is the character array valid character length, excluding the end of the '/0 ' sort function contained in the header file is #include<algorithm> C + + standard library, call the standard library sorting method can
You don't have to know how it's going to happen inside, just the results we want. II)The sort function has three parameters: (1) The first is the starting address of the array to sort.

(2) The second is the end of the address (the last to be sorted) (3) The third parameter is the method of sorting, can be from large to small but also small to large, you can not write a third parameter, at this time the default sorting method is from small to large sort. #include <list> lists elements are stored sequentially in the list.
It allows for fast insertions and deletions compared to vectors (vectors), but random access is slower. Assign () to the list assignment back () returns the last element front () returns the first element clear () deletes all elements empty () returns True if the list is empty pop_back () deletes the last element Pop_fro NT () Delete the first element push_back () add an element to the end of the list Push_front () add an element size () to the head of the list to return the number of elements in the list sort () to the list sort () swap two Lis T unique () deletes the repeating element begin () of the list to return the iterator end () that points to the first element erase () deletes an element Get_allocator () returns the list's Configurator insert () inserts a element to list max_size () returns the maximum number of elements that the list can hold merge () merges two list rbegin () returns the reverse iterator to the first element remove () deletes the element from the list remove_if () by the specified criteria The element rend () to the reverse iterator at the end of the list resize () change the size of the list reverse () invert the elements of the list splice () Merge two list #include <bits/stdc++.h> Magnum
 header file int p[len];memset (p,0,sizeof (int) *len);//Initialize all arrays to 0

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.