C++ 容器 new 删除问题

来源:互联网 发布:快速排序算法c语言 编辑:程序博客网 时间:2024/06/06 18:07
#include<iostream>#include<vector>using namespace std;int main(){    std::vector<int*> a;    int* b = new int(10);    a.push_back(b);    for(std::vector<int*>::iterator it = a.begin(); it != a.end();)    {        std::cout << *(*it) << std::endl;        delete *it;        (*it) = NULL;        it = a.erase(it);    }       return 0;}

0 0
原创粉丝点击