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

📄 09-1.cpp

📁 effective stl 源代码 code
💻 CPP
字号:
//
// Example from ESTL Item 9
//

#include <list>
#include <vector>
#include <set>
#include <iostream>
#include "ESTLUtil.h"

int main()
{
	using namespace std;
	using namespace ESTLUtils;

	const int vals1[] = { 1, 1963, 2, 3, 4, 1963, 5};

	const int nvals1 = sizeof vals1 / sizeof(int);

	{
		vector<int> v(vals1, vals1 + nvals1);

		cout << "Before:" << endl;
		printContainer("v", v);
		
		v.erase( remove(v.begin(), v.end(), 1963),	// the erase-remove idiom is
							v.end());				// the best way to get rid of
													// elements with a specific
													// value when c is a vector,
		printContainer("after remove, v", v);		// string, or deque	
	}

	{
		list<int> l(vals1, vals1 + nvals1);

		cout << "Before:" << endl;
		printContainer("l", l);
		
		l.remove(1963);								// the remove member function is the
													// best way to get rid of elements with
													// a specific value when c is a list
		printContainer("after remove, l", l);
	}

	{
		set<int> s(vals1, vals1 + nvals1);

		cout << "Before:" << endl;
		printContainer("s", s);
		
		s.erase(1963);								// the remove member function is the
													// best way to get rid of elements with
													// a specific value when c is a list
		printContainer("after erase, s", s);
	}
	return 0;
}

⌨️ 快捷键说明

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