[Solved] Find the x,y index of a value in a vector of vectors – C++


Doing a simple loop should work. Horribly in-efficient though.

Target is the value you are looking for while arr is the array you are looking for it in.

int x = -1; int y = -1;
for(int i = 0 ; i < arr.size() ; i++){
    for(int j = 0 ; j < arr.size() ; j++ ){
        if(arr[i][j] == target){
            x = i ; y = j;
            break;
        }
    }
    if(x != -1 && y != -1)
        break;
    }
}

1

solved Find the x,y index of a value in a vector of vectors – C++