1.练习代码-vector容器常规操作

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

void print(vector<int>);

int _tmain(int argc, _TCHAR* argv[])
{
	vector<int> array_v;
	array_v.push_back(1);
	array_v.push_back(6);
	array_v.push_back(6);
	array_v.push_back(3);

	vector<int>::iterator itor;
	vector<int>::iterator itor2;
	itor = array_v.begin();

	array_v.erase(remove(array_v.begin(), array_v.end(), 6), array_v.end());

	print(array_v);
	return 0;
}

void print(vector<int> v)
{
	cout << "\n vector size is: " << v.size() << endl;
	vector<int>::iterator p = v.begin();
}

2.关键点分析

2.1处理过程

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

void print(vector<int>);

int _tmain(int argc, _TCHAR* argv[])
{
	vector<int> array_v;
	array_v.push_back(1); //在容器尾部添加数据1
	array_v.push_back(6); //在容器尾部添加数据6
	array_v.push_back(6); //在容器尾部添加数据6
	array_v.push_back(3); //在容器尾部添加数据3

	vector<int>::iterator itor; //定义指向容器数据的指针p
	itor = array_v.begin(); //将p指向容器数据的头部

	array_v.erase(remove(array_v.begin(), array_v.end(), 6), array_v.end()); //使用erase方法和remove方法进行数字6删除

	print(array_v); //打印删除2个6之后的容器大小
	return 0;
}

void print(vector<int> v)
{
	cout << "\n vector size is: " << v.size() << endl;
	vector<int>::iterator p = v.begin();
}

2.2运行结果

【小练习】STL模板与容器_容器2

相关文章:

  • 2022-01-10
  • 2021-11-20
猜你喜欢
  • 2021-12-31
  • 2021-08-06
  • 2021-07-28
  • 2022-12-23
  • 2022-01-10
  • 2021-06-19
  • 2022-01-06
相关资源
相似解决方案