单独删除std::vector <std::vector<string> > 的所有元素

下面为测试代码:

1.创建

std::vector< std::vector<string> > vc2;

2.初始化 

    std::vector<string> vc; 
    vc.push_back("v11"); 
    vc.push_back("v12"); 
    vc.push_back("v13");

    std::vector<string> v2; 
    v2.push_back("v21"); 
    v2.push_back("v22"); 
    v2.push_back("v23");

    std::vector<string> v3; 
    v3.push_back("v21"); 
    v3.push_back("v22"); 
    v3.push_back("v23");

    vc2.push_back(vc); 
    vc2.push_back(v2); 
    vc2.push_back(v3);

3.执行删除操作

    for (std::vector<std::vector<string> >::iterator i = vc2.begin(); i != vc2.end();) { 
        for (std::vector<string>::iterator j = i->begin(); j != i->end(); ) { 
            j = i->erase(j); 
        } 
        i = vc2.erase(i); 
    }

 

posted @ 2015-04-17 15:09  leungcnblogs  阅读(651)  评论(0编辑  收藏  举报