-2

I have a 2d vector of chars that is declared by user input. but, how would i return this 2d vector of chars?

I know i need 2 for loops, but how would i, first get the size of how many vectors there are. second, find the size of one of the vectors in the 2d vector.

For example, lets say the user inputs:

     .........
     .........
     ....x....
     .........
     .........

how would i get the height and the width of this 2d vector and print it out?

what i have so far is this:

     for (int i = 0; i < data.size(); i ++) {
            for (int j = 0; j < data<data.size()>>; j++) {

            }
        }

Also, the user is allowed to input files that are larger than the one mentioned. Thats why i cant use an already declared variable.

I think a better question would be " how do i get the length of the 2d vector, and the height of one of the vectors to print out the entire thing? "

2 Answers2

0

You mean:

for (int j = 0; j < data[i].size(); j++) {
Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62
0

You can get the height/rows with data.size() and the columns for each row with data[row].size().

for(i = 0; i < vec2d.size(); ++i) {
    for(j = 0; j < vec2d[i].size(); ++j) {
        // do whatever with vec2d
    }
}
Austin Stephens
  • 401
  • 4
  • 9