C + + sequential containers (3)

Source: Internet
Author: User

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)

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.