我对 C++ 很陌生,并且得到了一项仅使用 STL 容器制作矩阵的任务。我使用了向量(列)的向量(行)。我遇到的问题是在“写”操作中——我可能只使用基于迭代器的实现。问题很简单:它什么也没写。
我已经用一个填充了不同值的矩阵进行了测试,虽然迭代器最终恰好位于正确的位置,但它并没有改变值。
这是我的代码:
void write(matrix mat, int row, int col, int input)
{
    assert(row>=0 && col>=0);
    assert(row<=mat.R && col<=mat.C);
    //I set up the iterators.
    vector<vector<int> >::iterator rowit;
    vector<int>::iterator colit;
    rowit = mat.rows.begin();
    //I go to the row.
    for(int i = 0; i<row-1; ++i)
    {   
        ++rowit;
    }
    colit = rowit->begin();
    //I go to the column.
    for(int j = 0; j<col-1; ++j)
    {
        ++colit;
    }
    *colit = input; //Does nothing.
}
我在看什么?谢谢。