⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 《C++ STL开发技术引导》配套光盘 聆听大师级的指点
💻 CPP
字号:
#include <algorithm>
#include <vector>
#include <iostream>

int main(void){
	using namespace std;
	//初始化向量v={1, 8, 8, 8, 6, 6, 8}
	vector<int> v;
	v.push_back(1);
	v.push_back(8);
	v.push_back(8);
	v.push_back(8);
	v.push_back(6);
	v.push_back(6);
	v.push_back(8);
	//查找子序列{8, 8, 8}
	vector<int>::iterator iLocation;
	iLocation=search_n(v.begin(), v.end(), 3, 8);
	if(iLocation != v.end())
		cout << "在v中找到3个连续的元素8" << endl;
	else 
		cout << "v中没有3个连续的元素8" << endl;
	//查找子序列{8, 8, 8, 8}
	iLocation=search_n(v.begin(), v.end(), 4, 8);
	if(iLocation != v.end())
		cout << "在v中找到4个连续的元素8" << endl;
	else 
		cout << "v中没有4个连续的元素8" << endl;
	//查找子序列{6, 6}
	iLocation=search_n(v.begin(), v.end(), 2, 6);
	if(iLocation != v.end())
		cout << "在v中找到2个连续的元素6" << endl;
	else 
		cout << "v中没有2个连续的元素6" << endl;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -