Operation of vectors in the "STL" standard library

Source: Internet
Author: User
#include <iostream> #include <vector> #include <iterator> int main () {int ar[10] = {11, 12, 13, 14, 1
	5, 16, 17, 18, 19, 20};
	Std::vector<int> V (AR, ar+10);

	Std::vector<int> v1 (5, 88); 
	Traverse Vector for (std::vector<int>::iterator it=v.begin (); It!=v.end (); ++it) std::cout << *it << "";

	Std::cout << Std::endl;
	Adds a member to the container, and the vector does not support V.push_back (21) that was previously inserted;
	For (Std::vector<int>::iterator It=v.begin (); It!=v.end (); ++it) std::cout << *it << "";

	Std::cout << Std::endl;
	Insert Value Method 1 V.insert (V.begin () +1, 99);
	For (Std::vector<int>::iterator It=v.begin (); It!=v.end (); ++it) std::cout << *it << "";
	Std::cout << Std::endl;
	Insert Value Method 2 V1.insert (V1.begin () +1, V.begin () +2, V.begin () +5);
	For (Std::vector<int>::iterator It=v1.begin (); It!=v1.end (); ++it) std::cout << *it << "";

	Std::cout << Std::endl;
	Assignment V1.assign (6, 77); for (std::vector<Int>::iterator It=v1.begin (); It!=v1.end ();
	++it) std::cout << *it << "";

	Std::cout << Std::endl;	Query Value Std::cout << v.front () << "";	The 0th member of v Std::cout << v.back () << "";	The last member of V Std::cout << v.at (3) << "";		V's fourth member Std::cout << v[3] << "";
	
	V's fourth member Std::cout << Std::endl;
	Delete value V.pop_back ();
	For (Std::vector<int>::iterator It=v.begin (); It!=v.end (); ++it) std::cout << *it << "";

	Std::cout << Std::endl;
	V.erase (V.begin () +2, V.begin () +4);
	For (Std::vector<int>::iterator It=v.begin (); It!=v.end (); ++it) std::cout << *it << "";

	Std::cout << Std::endl;
return 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.