低级错误

#include <vector>
int main()
{
    std::vector<int> vecT;
    vecT.push_back(1);
    vecT.push_back(2);
    vecT.push_back(3);

    for (std::vector<int>::iterator it = vecT.begin(); it != vecT.end(); ++it)
    {
        while (it != vecT.end())
        {
            ++it;
        }
    }
    return 0;
}

我原以为这段小程序没有问题,当while循环退出来的时候it已经是vecT.end()了,而在后面执行的是++it,对vecT.end()执行++直接报错,连最简单的for循环执行顺序都弄错了。闭门思过。

posted @ 2015-11-01 13:13  zzyoucan  阅读(279)  评论(0编辑  收藏  举报