So I am trying to write a simple code that will take in 2 strings from the users. It then takes the length of the strings using length() and creates a matrix (2d vector) of ints based on the lengths. I then need to set the values of the last row and last column to have values of powers of 2. If the entered strings are "happy" & "sad" the resulting matrix should be:
0 0 0 0 0 6
0 0 0 0 0 4
0 0 0 0 0 2
10 8 6 4 2 0
I am generating the matrix like this:
vector<vector<int>> opt;
unsigned int x, y;
x = (sequenceOne.length()) + 1;
y = (sequenceTwo.length()) + 1;
unsigned int p,q;
opt.resize(y, vector<int>(x, 0)); // resizes the matrix
When I try to change values in the matrix with:
opt[2][2] = 5;
It works fine, but when I go to access the last row last column like this:
opt[x][y]
It tells me "Expression: vector subscript out of range" I think it has something to do with the getting the length of the strings to use as the values, but I can't for the life of me figure out why that would cause an issue. I have tried making the subscripts different variables, different orders, and stuff like opt[x-1][y-1] but the error still occurs.
I'm not sure if it matters but I am using MS VS2012.