Search code examples
c++vectoriteratorerase

c++ 2D vector(matrix) how to delete the nth row?


Here is the 2d vector [[1,3],[2,6],[8,10],[15,18]] I want to delete the 2nd row which is [2,6] I tried following to erase the 1st row

matrix[1].erase(intervals[1].begin(),intervals[1].end());

after erasing the row when I printed the matrix, I got [[1,3],[],[8,10],[15,18]] I wanted to remove the brackets also, how to do that?


Solution

  • From what you showed, I believe the correct code would be

    matrix.erase( matrix.begin()+1 );