Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8229255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:44:22+00:00 2026-06-07T16:44:22+00:00

How to resize a vector of vector containing integer values. std::vector<std::vecotr<int>> MyVector; int value

  • 0

How to resize a vector of vector containing integer values.

std::vector<std::vecotr<int>> MyVector;
int value = 10;

//need to insert values as 2 rows and 3 columns, like
//Myvector[0][0] = value;
//Myvector[0][1] = value;
//Myvector[0][2] = value;
//Myvector[1][0] = value;
//Myvector[1][1] = value;
//Myvector[1][2] = value;

// ......
//here i have to resize the vector size to 4 rows and 5 cols using resize() function.

MyVector.resize(.......); //Hoe is this possible.

The first problem is , I have to insert the values as 2 rows and 3 columns. how can I use push_back function for this purpose. After that need to resize to the specified size. Since it a vector of vector I am getting worried about this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:44:23+00:00Added an answer on June 7, 2026 at 4:44 pm

    You can think of a vector of vectors as a matrix where the member vectors are “rows”.

    int main()
    {
        std::vector<std::vector<int> > MyVector;
        //Create a row:
        std::vector<int> subVector;
        subVector.push_back(1);
        subVector.push_back(2);
        //put the row into the vector:
        MyVector.push_back(subVector);
        //create another row:
        subVector.clear();
        subVector.push_back(3);
        subVector.push_back(4);
        //put the second row into the vector
        MyVector.push_back(subVector);
        //access the first row and add an element to it:
        MyVector[0].push_back(6);
        //access the second row and add an element to it:
        MyVector[1].push_back(6);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets we have std::vector <std::vector <int>> myVec; myVec.resize(100); myVec[0].push_back(1); myVec[0].push_back(2); When I break the
Let's we have std::vector <std::vector <unsigned short int>> face; face.resize(nElm); Its OK to resize()
I have some std::vector and I have to resize it with some default value.
int main () { vector<int> myvector; vector<int>::iterator it; // set some values: for (int
I'm having a problem resizing my two dimensional vectors. std::vector<std::vector<NavigationNode>> *nodes; nodes->resize(sizex); for(unsigned int
I have a std::vector of values for which I know the maximum size, but
There is a vector of vectors: std::vector <std::vector <float> > VoV; VoV.resize(num); // num
If I allocated an std::vector to a certain size and capacity using resize() and
Lets say i have vector of vectors vector< vector<int> > bigTable; vector<int> data; data.resize(2);
I have following std::vector declaration: std::vector<std::vector<std::vector<int> > > m_input; I am initializing it as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.