Effective STL 为包含指针的关联容器指定比较类型
生活随笔
收集整理的這篇文章主要介紹了
Effective STL 为包含指针的关联容器指定比较类型
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// 為包含指針的關聯容器指定比較類型.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;}轉載于:https://www.cnblogs.com/wangyaning/p/4237011.html
總結
以上是生活随笔為你收集整理的Effective STL 为包含指针的关联容器指定比较类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乌镇西栅游览车多少钱
- 下一篇: 电脑桌多少钱啊?