国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 皋兰县| 霸州市| 芷江| 牟定县| 临泽县| 新巴尔虎左旗| 夹江县| 横峰县| 明星| 靖边县| 大埔区| 安图县| 全南县| 民丰县| 三明市| 上虞市| 泸定县| 平顶山市| 和政县| 巴南区| 襄樊市| 黔东| 赤壁市| 通化县| 襄城县| 额济纳旗| 南漳县| 满洲里市| 湛江市| 宜君县| 财经| 南皮县| 永靖县| 南昌县| 凤台县| 青铜峡市| 沂水县| 阳江市| 汉沽区| 涡阳县| 泸溪县|