About the use of vector<vector<int> > in C + +

Source: Internet
Author: User

1. Definition

Vector<vector<int>> a;//Error Definition method vector<vector<int> > a;//definition

2. Inserting elements

If you want to define a = [[0,1,2],[3,4,5]], then:

Correct insertion method vector<vector<int> > A;//a.push_back must be vectorvector<int> B; B.push_back (0); B.push_back (1); B.push_back (2); A.push_back (B); B.clear (); B.push_back (3); B.push_back (4); B.push_back (5); A.push_back (B);

Wrong insertion method vector<vector<int> > A; A[0].push_back (0); A[0].push_back (1); A[0].push_back (2); A[1].push_back (3); A[1].push_back (4); A[1].push_back (5);

3. Length

The number of vector elements in vector<vector<int> >a len = a.size ();//vector<vector<int> > The length of the vector element in a, Len = A[i].size ();

  

About the use of vector<vector<int> > in C + +

Related Article

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.