Is there a way to declare a two-dimensional array with two variables? I need to be able to pass the array back and forth between functions. I've tried using vectors and dynamic arrays, but I don't like them because I can't see the value of any one element using Xcode's debugger, which will make debugging a real pain.
Are you sure you can't see individual values? In Visual Studio you can click a plus icon to expand the vector and display its members. Are you sure this can't be done in XCode?
You're right. I wrote a quick little test application, and sure enough, I can expand a 1D vector in the debugger and see its contents. So I rewrote it to use a 2D vector, and when I expand the outer vector I get a list of more vectors (as expected) . But when I expand any of those inner vectors, I get nothing. I'm not sure if this is a bug in Xcode; does it work in Visual Studio? To save time, you can just copy-paste this test code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <vector>
usingnamespace std ;
int main (int argc, char * const argv[]) {
vector <vector <long> > vector2D ;
vector2D.resize (8) ;
for (int i = 0 ; i <= 8 ; i ++ ) {
vector2D [i] .resize (8) ;
}
for (int i = 0 ; i < 8 ; i ++ ) {
for (int j = 0 ; j < 8 ; j ++ ) {
vector2D [i] [j] = i * j ;
}
}
return 0 ;
}