lundi 4 décembre 2017

displaying a vector of deques in columns

I'm trying to display a vector of deques (vector < deque < int > > v) like this

v.at(0).at(0) v.at(1).at(0) v.at(2).at(0) v.at(3).at(0)
v.at(0).at(1) v.at(1).at(1) v.at(2).at(1) v.at(3).at(1)
v.at(0).at(2) v.at(1).at(2) v.at(2).at(2) v.at(3).at(2)
              v.at(1).at(3)               v.at(3).at(3)
                                          v.at(3).at(4)

The first part of the vector is fixed at 7, the size of the actual columns are dynamic however depending on what the user chooses to do.

I was attempting something like

int row = 0;
int column;

for (column = 0; column < v.at(row).size(); column++){
      cout << "v["<< row <<"]["<< column << "]" << v.at(row).at(column) << "\t";
  while (row < v.size()){
    cout << endl;      
    row++;
  }
}

I'm getting errors like

libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector
make: *** [Pile.h] Abort trap: 6

Having one of those blah brain days. Can someone help me print this out the way I want it?

Aucun commentaire:

Enregistrer un commentaire