国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

淺談c++ vector和map的遍歷和刪除對象

2020-01-26 14:20:20
字體:
來源:轉載
供稿:網友

示例如下:

// Aa.cpp : Defines the entry point for the console application.#include "stdafx.h"#include <vector>#include <map>#include <iostream>using namespace std;int main(int argc, char* argv[]){printf("Hello World!/n");vector<int> a; //創建一個對象a.push_back(1);a.push_back(2);a.push_back(3);vector<int>::iterator iter;for( iter = a.begin(); iter != a.end(); ++iter ) //遍歷和刪除一個對象{if( (*iter) == 2 ){a.erase(iter);printf("del is item;");break;}}vector<int>* b = new vector<int>();b->push_back(1);b->push_back(2);b->push_back(3);vector<int>::iterator iterr;for( iterr = b->begin() ; iterr!= b->end() ; iterr++)//通過new 一個對象刪除{if( (*iterr) == 2 ){b->erase(iterr);printf("del is new item");break;}}map<int,int> mapTest;mapTest[0] = 1;mapTest[1] = 2;mapTest[2] = 3;map<int,int>::iterator mapIter;for( mapIter = mapTest.begin() ; mapIter != mapTest.end() ; ++mapIter ){std::cout << mapIter->first<<"-----"<<mapIter->second<< std::endl;}system("pause");return 0;}

以上就是小編為大家帶來的淺談c++ vector和map的遍歷和刪除對象全部內容了,希望大家多多支持武林網~

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 楚雄市| 方城县| 台江县| 奉节县| 徐水县| 曲周县| 且末县| 梁山县| 浦东新区| 东莞市| 同德县| 涿州市| 福建省| 昆明市| 安仁县| 双柏县| 璧山县| 宁津县| 汉川市| 左权县| 封丘县| 西峡县| 台北县| 庆元县| 改则县| 长治市| 湾仔区| 鲁山县| 正阳县| 荔浦县| 自贡市| 偃师市| 锡林郭勒盟| 阿瓦提县| 五寨县| 武定县| 容城县| 林西县| 都昌县| 阳城县| 新疆|