In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to use C++ 's vector". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Create object
In C++, there are 4-6 methods for creating objects in official documents. Bloggers here introduce four of the most commonly used methods. At the same time, bloggers will save some places that are different from the source documents in order to make them easy to use first.
Create directly, that is, just like the class definition object, the official declaration is: explicit vector ();, where explict means that implicit type conversion is not supported.
Example:
Vector v1; / / create an int type sequence table v1 * * vector v2; / / create a char type sequence table v2 * * vector v3; / / create a double type sequence table v3
By passing n valals to define the object, you can have n val as soon as the object is created, which is officially declared as: explicit vector (size_type n, const value_type& val = value_type ();, where value_type is the type we need.)
Example:
Vector v1 (10jue 9); / / create an int type sequence table v1 with 10 9 position vectors v2 (v1.begin (), v1.begin () + 6); / / create an int type sequence table v2 with 6 9 in it
Create objects in the form of iterator intervals, officially declared as: template vector (InputIterator first, InputIterator last).
Example:
Vector v1 (10jue 9); / / create an int type sequence table v1 with 10 9 position vectors v2 (v1.begin (), v1.begin () + 6); / / create an int type sequence table v2 with 6 9 in it
Create objects through ready-made objects of the same type, officially declared as: vector (const vector& x);.
Example:
Vector v1 (10jue 9); / / create an object by the previous method; vector v2 (v1); / / create object v2, whose content is exactly the same as v1. Iterator
After the baptism of string in the previous sections, I believe you all have a good understanding of iterators, so let's introduce the usage directly to the point:
Ordinary iterator interface: begin () and end (), respectively, where begin () is the first element position and end () is the next position of the last element position
Reverse iterator interfaces: rbegin () and rend (), respectively, where rbegin () is the position of the last element and rend () is the position before the first element.
Example:
Vector v1. Pushback (1); v1.push_back (2); v1.push_back (3); v1.push_back (4); / / these four steps roughly mean inserting 1 2 3 4vector::iterator it = v1.begin (); while (it! = v1.end ()) {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.