10_21.cpp

来自「C++语言程序设计案例教程,郑莉编的书」· C++ 代码 · 共 26 行

CPP
26
字号
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include <deque>
#include <vector>
using namespace std;
int main()
{	list<string> sList;	vector<string> sVect;	deque<string> sDeq;
sList.insert(sList.end(), "Red");	sList.insert(sList.end(), "Green");
	sList.insert(sList.end(), "Yellow");
	sVect.insert(sVect.end(), "Red");	sVect.insert(sVect.end(), "Green");
	sVect.insert(sVect.end(), "Yellow");	sVect.insert(sVect.end(), "White");
	sDeq.insert(sDeq.end(), "Red");	sDeq.insert(sDeq.end(), "White");
	if (equal(sList.begin(), sList.end(),sVect.begin()))//使用通用算法equal
		cout<<"The content in sList is equal to sVect"<<endl;
	if (!equal(sDeq.begin(), sDeq.end(),sList.begin()))	//使用通用算法equal
		cout<<"The content in sDeq is not equal to sList"<<endl;
	pair<deque<string>::iterator, list<string>::iterator>
		pair1 = mismatch(sDeq.begin(), sDeq.end(),sList.begin());//使用通用算法mismatch
	if (pair1.first != sDeq.end())
		cout << "First disagreement in sDeq and sList:  "<< *(pair1.first) 
		<< " and " << *(pair1.second)<< endl;
	return 0;
}

⌨️ 快捷键说明

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