C++ vector遍历删除

int _tmain(int argc, _TCHAR* argv[])

{

    vector a ;//= {12, 23, 34, 45, 56, 67, 78, 89};

a.push_back(10);

a.push_back(40);

a.push_back(10);

a.push_back(10);

a.push_back(10);

    for (auto iter = a.begin(); iter != a.end(); ) {

        if (*iter > 30) {

            iter = a.erase(iter);

        }

        else

            ++iter;

    }

感谢C海摸鱼的指正

你可能感兴趣的:(C++ vector遍历删除)