1、比如一些电话号码比较,如果文件比较大考虑插桩!
2、时间段重叠运算。
3、数据变化处理。
#include "stdafx.h"
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
struct compare
{
bool operator ()(string s1,string s2)
{
return s1 > s2;
}///自定义一个仿函数
};
int main()
{
typedef std::set<string,compare> _SET;
_SET s;
s.insert(string("sfdsfd"));
s.insert(string("apple"));
s.insert(string("english"));
s.insert(string("dstd"));
cout<<"s1:"<<endl;
std::set<string,compare>::iterator it = s.begin();
while(it!=s.end())
cout<<*it++<<" ";
cout<<endl<<"s2:"<<endl;
_SET s2;
s2.insert(string("abc"));
s2.insert(string("apple"));
s2.insert(string("english"));
it = s2.begin();
while(it!=s2.end())
cout<<*it++<<" ";
cout<<endl<<endl;
string str[10];
string *end = set_intersection(s.begin(),s.end(),s2.begin(),s2.end(),str,compare());
cout<<"result of set_intersection s1 <> s2:"<<endl;
string *first = str;
while(first<end)
cout <<*first++<<" ";
cout <<endl;
}
分享到:
相关推荐
c++11引入了std::bind及std::function,实现了函数的存储和绑定,即先将可调用的对象保存起来,在需要的时候再调用。定义了SignalObject信号类和SlotObject槽类,其中信号类中的 std::function(int)> _call就是要...
代码重点是hash_table,附加std::map与其做对比,实现的是一条sql语句:select c_nationkey, c_mktsegment, count(*), max(c_acctbal) from aaa_customer_1g group by c_nationkey, c_mktsegment order by c_...
std::list没有[]函数或Get()函数,又不能总是front()的方式排出,如何遍历获得其中的元素呢?比如 遍历显示元素内容为例 ,用两种方式实现。
本程序提供了std::string 类型的Format格式化函数,以及两种格式化string字符串的方法,主方法在str.hpp文件中,测试文件在string_format.cpp中,已测试可用
std::string、char*、const char*转托管byte数组或托管字符串String std::string、char*、const char*是C++中三个不同的字符串表示方式,它们都可以转换为托管的byte数组或字符串String,但是在C++/CLI中,它们的...
一个详细全面的关于vector排序的例子。 涉及到 如何继承std::binary_function, CString, bool>、如何重载operator().
使用C++类模板实现的std::vector容器。 对于学习动态数组有很大的帮助。
在C++中,使用文件流(std::ifstream 和 std::ofstream)可以方便地读取和写入文本文件。下面是一些示例代码,展示了如何使用这些文件流来操作文本文件。 读取文本文件 cpp #include <iostream> #include ...
linux 下 std::list的使用
friend std::ostream & operator(std::ostream& os, const TinyString<K>& str); template, size_t L> friend bool operator == (const TinyString<K>& s1, const TinyString<L>& s2); //...... uint8...
前面两讲《C++11 并发指南二(std::thread 详解) 》,《C++11 并发指南三(std::mutex 详解) 》分别介绍了 std::thread 和 std::mutex,相信读者对 C++11 中的多线程编程有了一个最基本的认识,本文将介绍 C++11 标准...
cmake 、代理模式与pimpl模式混用实例、std::move、std::forward()应用。用于学习C++设计模式,cmake程序编译。
C++11中提供了异步线程接口std::async,std::async是异步编程的高级封装,相对于直接使用std::thread,std::async的优势在于: 1、std::async会自动创建线程去调用线程函数,相对于低层次的std::thread,使用起来非常...
上一篇《C++11 并发指南二(std::thread 详解) 》中主要讲到了 std::thread 的一些用法,并给出了两个小例子,本文将介绍 std::mutex 的用法。 Mutex 又称互斥量,C++ 11中与 Mutex 相关的类(包括锁类型)和函数都...
C++11中的std::async是个模板函数。std::async异步调用函数,在某个时候以Args作为参数(可变长参数)调用Fn,无需等待Fn执行完成就可返回,返回结果是个std::future对象。Fn返回的值可通过std::future对象的get成员...
主要介绍了C++ 11 std::function和std::bind使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
std::future所引用的共享状态不能与任何其它异步返回的对象共享(与std::shared_future相反)( std::future references shared state that is not shared with any other asynchronous return objects (as opposed to ...
摘要:在这篇文章里,将从各个角度介绍下std::array的用法,希望能带来一些启发。 td::array是在C++11标准中增加的STL容器,它的设计目的是提供与原生数组类似的功能与性能。也正因此,使得std::array有很多与其他...
std::condition_variable 是 C++11 标准中一个重要的同步机制,广泛应用于多线程编程中。它提供了一个高效的方式来实现线程同步,提高了程序的性能和可靠性。 相关知识点: * std::condition_variable 的使用 * ...
std::ios::sync_with_stdio(false); cin.tie(0); return 0; } 可以增强cin和cout的效率。 在做acm一些题时,经常出现 数据集超大造成 cin读入过多 超时的情况。 这是因为在c++中cin,cout虽然方便但是效率低。 ...