Effective STL 为包含指针的关联容器指定比较类型

本文涉及的产品
容器镜像服务 ACR,镜像仓库100个 不限时长
简介: // 为包含指针的关联容器指定比较类型.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include using namespace std;struct StringPtrLess: p...
// 为包含指针的关联容器指定比较类型.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <set>
#include <string> 
#include <iostream>

using namespace  std;


struct  StringPtrLess:
	public binary_function<const string*, const string*, bool>
	{
		bool operator()(const string *ps1, const string *ps2) const
		{
			return *ps1 < *ps2;
		}
	};


typedef set<string*, StringPtrLess> StringPtrSet;
StringPtrSet ssp;

int main()
{

	
	

	ssp.insert(new string("apple"));
	ssp.insert(new string("toy"));
	ssp.insert(new string("cat"));


	for (StringPtrSet::const_iterator i = ssp.begin();i != ssp.end();++i)
	{
		cout<<(**i)<<endl;
	}


	getchar();
	return 0;


}


相关文章
|
30天前
|
存储 C语言
文件的类型指针
文件的类型指针
13 0
|
30天前
|
编译器 C语言
void的指针类型
void的指针类型
8 0
|
1月前
|
存储 程序员 C++
在C++编程语言中指针的作用类型
在C++编程语言中指针的作用类型
14 0
|
23天前
|
设计模式 程序员 C++
【C++ 泛型编程 高级篇】C++模板元编程:使用模板特化 灵活提取嵌套类型与多容器兼容性
【C++ 泛型编程 高级篇】C++模板元编程:使用模板特化 灵活提取嵌套类型与多容器兼容性
241 2
|
3月前
|
C语言
C语言指针类型,8个例子给你讲明白
C语言指针类型,8个例子给你讲明白
40 0
|
28天前
|
C语言
Void 指针类型
Void 指针类型
8 0
|
1月前
|
存储 C语言
C语言指针类型和空类型详解
C语言指针类型和空类型详解
21 0
|
1月前
|
存储 C++
在C++语言中函数指针的作用类型
在C++语言中函数指针的作用类型
10 0
|
1月前
|
存储 C++ 索引
在C++语言中容器的选择类型
在C++语言中容器的选择类型
11 0
|
1月前
|
存储 安全 C++
深入理解C++ STL中的vector容器
深入理解C++ STL中的vector容器
12 0