Answers for "how to make a vector of vectors"

C++
3

get values from a vector of vectors c++

#include <iostream>
#include <vector>
using namespace std;  

int main()
{
    vector<vector<int> > buff;

    for(int i = 0; i < 10; i++)
    {
        vector<int> temp; // create an array, don't work directly on buff yet.
        for(int j = 0; j < 10; j++)
            temp.push_back(i); 
 
        buff.push_back(temp); // Store the array in the buffer
    }

    for(int i = 0; i < buff.size(); ++i)
    {
        for(int j = 0; j < buff[i].size(); ++j)
            cout << buff[i][j];
        cout << endl;
    }

    return 0;
}
Posted by: Guest on July-18-2020
0

create vectors of vectors c++

typedef std::vector<std::vector<double> > Matrix;

Matrix matrix = { {0.1,1.1,.2},
                 {.4,.5,.6}, 
                 {.8,.9,.10}
                };
// Just initilization:
int rows = 3;
int cols = 3;
Matrix m3(rows, std::vector<double>(cols) );
Posted by: Guest on February-12-2021

Code answers related to "how to make a vector of vectors"

Browse Popular Code Answers by Language