vendredi 6 octobre 2017

Vector out of range error

int main(int argc, const char * argv[]) {

// Create a matrix --------------------------------------------------------

cout << "Creating a matrix(row and colum) " << endl;

cout << "Enter row number: ";

cin  >> numRows;

cout << "Enter colum number: ";

cin  >> numCols;
cout << endl;
matrixInit (vector2D, numRows, numCols);

//-------------------------------------------------------------------------

// Create a token type vector ---------------------------------------------

cout << "Enter the text: " << endl;

getline(cin,inputString);

getTokenFreqVec(inputString, tokenVector);

cout << endl;

//-------------------------------------------------------------------------

return 0;

}

I get this error after I enter all the data to create the matrix. Here is the out put:

Creating a matrix(row and colum)

Enter row number: 2

Enter colum number: 2

Enter the value for row 1 column 1

1

Enter the value for row 1 column 2

2

Enter the value for row 2 column 1

3

Enter the value for row 2 column 2

4

The matrix you have created:

1 2

3 4

Enter the text:

libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: vector (lldb)

If I create the token type vector 1st, there is no error.

Anybody know the reason?

Aucun commentaire:

Enregistrer un commentaire