c++ - 2D vector push_back -
i have code below , i'm strugling add values vector. end goal itterate through list , each itteration add value 2 rows of vector i'm strugling understand how push_back 2d vector.
std::vector<std::vector<int> >nns; int = 5; nns.push_back(i, i); for(int = 0; <nns.size(); i++) { for(int j = 0; j < nns[i].size(); j++) { std::cout << nns[i][j] << std::endl; } } how add 1 column vector? vector[0][0] = 0 vector[1][0] = 0?
answer provided algirdas works perfectly.
#include <iostream> #include <vector> using namespace std; int main() { std::vector<std::vector<int> > nns; int = 5; nns.push_back(std::vector<int>{i}); (int = 0; < nns.size(); i++) { (int j = 0; j < nns[i].size(); j++) { std::cout << nns[i][j] << std::endl; } } }
Comments
Post a Comment