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

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

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

2020-05-23 13:56:50
字體:
供稿:網(wǎng)友

示例如下:

// 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; //創(chuàng)建一個(gè)對象a.push_back(1);a.push_back(2);a.push_back(3);vector<int>::iterator iter;for( iter = a.begin(); iter != a.end(); ++iter ) //遍歷和刪除一個(gè)對象{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 一個(gè)對象刪除{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;}

以上就是小編為大家?guī)淼臏\談c++ vector和map的遍歷和刪除對象全部內(nèi)容了,希望大家多多支持VEVB武林網(wǎng)~


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 马龙县| 博罗县| 辉县市| 成武县| 青冈县| 长垣县| 时尚| 积石山| 聂拉木县| 孝昌县| 岐山县| 富平县| 新蔡县| 耒阳市| 林州市| 闵行区| 广水市| 太保市| 嘉义市| 惠水县| 陈巴尔虎旗| 疏勒县| 平罗县| 陆川县| 正宁县| 青浦区| 南宁市| 前郭尔| 含山县| 湖口县| 宁波市| 福清市| 崇文区| 炎陵县| 淅川县| SHOW| 新泰市| 阿城市| 沙湾县| 台安县| 饶阳县|