In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use vector in STL, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
What is 1.vector?
1.vector is a container that represents a variable size array.
2.vector uses continuous storage space to store elements.
3.vector uses dynamic allocation arrays to store its elements.
2.vector create object
The following are the four copy constructors for vector.
Vector v1 vector v2 (10, 8); / create an object with ten 8 v2 vector v3 (+ + v2.begin (),-- v2.end ()); / / copy construction through an iterator, which can add or subtract operation vector v4 (v3); / / copy construction string s ("hello world"); vector v5 (s.begin (), s.end ())
The process of creating an object by vector is the process of calling its constructor and copy construction, and we can also store the strings in s in container v5.
Note that vector cannot replace string because using vector requires manual printing of'\ 0', and vector does not support a series of operations such as + = and compare sizes.
3. Traversing vector
For a better demonstration, let's first define an array and pass data into it.
Vector v; v.push_back (1); v.push_back (2); v.push_back (3); v.push_back (4); v.push_back (5); (1) subscript traversal
The subscript traversal is readable and writable.
For (int I = 0; I < v.size (); iTunes +) {v [I] + = 1bank / can be modified because the returned value is a reference 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.