国产探花免费观看_亚洲丰满少妇自慰呻吟_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的遍歷和刪除對象全部內容了,希望大家多多支持武林網~

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 农安县| 图片| 荣昌县| 加查县| 新田县| 龙江县| 镇巴县| 绥棱县| 金沙县| 临汾市| 吉安市| 华蓥市| 峨眉山市| 介休市| 洞口县| 双辽市| 苏尼特右旗| 齐齐哈尔市| 西林县| 招远市| 瓦房店市| 大荔县| 法库县| 儋州市| 托克逊县| 宜昌市| 石阡县| 宁陕县| 尖扎县| 鄂托克前旗| 长乐市| 茶陵县| 洱源县| 连州市| 井研县| 得荣县| 禹城市| 泗水县| 都安| 射洪县| 蒲城县|