Hi,
I have just started learning C++, coming with good knowledge in Java and some other languages (assembly,CSP,haskell, etc.). I am trying to make a console application that reads user input for creating a matrix (using my own Matrix class) and methods for calculations of the array (multiplication, addition etc.). So far so good. However there is something that bothers me. I have created this method for getting the values of the array as a string.
Code:
void Matrix_::fillMatrix(string values) {
int counter_x = 0;
int counter_y = 0;
std::string temp = "";
for(int i = 0; i < values.size(); i++) {
if(values[i] != ' ') {
temp += values[i];
} else {
stringstream(temp) >> matrix[counter_x][counter_y];
temp = "";
counter_y++;
}
}
stringstream(temp) >> matrix[counter_x][counter_y];
this->display();
}
------------------
It is still unfinished though, because there is something that bothers me.
Code:
stringstream(temp) >> matrix[counter_x][counter_y];
. Matrix is my predefined 3x3 array. If i change the above code in something like :
Code:
stringstream(temp) >> matrix[counter_x][12];
it should give an error, since i am accessing an undefined element. However this is not the case. There is no error!! How is this possible? :O I have also tried this
Code:
cout << matrix[0][5];
and instead of getting an error, it prints a negative value (-1167...). Anyone can help me with that?
Thanks in advance.