samedi 5 septembre 2020

How to print vector

I am trying to assign and print vector<vector<int>> dynamically , However i cannot figure out how to do this i am stuck here is my program

#include<iostream>
#include<vector>
#include<string>
using namespace std;
class A {
public:
    vector<int> getVector(int s) {

        vector <int> A(s);
        for (int j = 0; j < s; j++) {
            A.push_back(j);
        }
        return A;
    }
};
int main() {
    A obj;
    int n = 5;
    vector<vector<int>> A;
    
    A.push_back(obj.getVector(n));     // pushes a vector on vector A
    A.push_back(obj.getVector(n - 1));

    vector<vector<int>> ::iterator it;
    it = A.begin();
    for (it; it != A.end(); it++) {
        cout << *it;
    }


    return 0;
}

Aucun commentaire:

Enregistrer un commentaire