简体   繁体   中英

How to assign size to a globally declared 2d vector in the main function in C++?

#include <bits/stdc++.h>
using namespace std;
vector< vector<int> >Adj;
int main()
{
    int n;
    cin>>n;
    Adj.assign(n);
}

This code doesn't work for assigning size to the vector.

  1. Use resize method 'Adj.resize(n)'. The function alters the container's content in actual by inserting or deleting the elements from it.
  2. If the given value of n is less than the size at present then extra elements are demolished.
  3. If n is more than current size of container then upcoming elements are appended at the end of the vector

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM