Vector size() function

Hi there,

Say I have a 2D vector of size 3:4 as follows:

vector< vector<double> > data( 3, vector<double>(4) );

How would I then use te size() function to return the size of the rows and columns to use in the for loop below, so that I don't have to manually specify the sizes?

1
2
3
4
5
6
7
for (int i = 0; i < ...... ; i++ )
    {
        for (int j = 0; j < ...... ; j++ )
            cout << setw( 7 ) << data[ i ][ j ];

        cout << endl;
    }


Thanks :)
Last edited on
Try these:
i < data.size(); j < data[i].size();
Thanks Bazzy, it works. I had to change int to size_t to prevent a warning.
Topic archived. No new replies allowed.