C++提高笔记(五)---STL容器(set/multiset、map/multimap)

2024-03-17 02:20

本文主要是介绍C++提高笔记(五)---STL容器(set/multiset、map/multimap),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、set / multiset容器

1.1set基本概念

简介:所有元素都会在插入时自动被排序

本质:set和multiset属于关联式容器,底层结构是用二叉树实现

set和multiset区别:

        set不允许容器中有重复的元素

        multiset允许容器中有重复的元素

1.2set构造和赋值

功能描述:创建set容器以及赋值

构造:

set<T> st;          //默认构造函数:
set(const set& st); //拷贝构造函数

赋值:

set& operator=(const set& st);//重载等号操作符
#include <iostream>
using namespace std;
#include<set>
//set容器构造和赋值
//构造:
//set<T> st;          //默认构造函数:
//set(const set& st); //拷贝构造函数
//赋值:
//set& operator=(const set& st);//重载等号操作符
void printSet(set<int>& s)
{for (set<int>::const_iterator it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout << endl;
}void test01()
{//创建set容器set<int>s1;//默认构造//插入数据,只有insert方式s1.insert(10);s1.insert(40);s1.insert(30);s1.insert(20);s1.insert(30);//遍历容器//set容器特点:所有元素插入时自动被排序//set容器不允许插入重复值printSet(s1);//拷贝构造set<int>s2(s1);printSet(s2);//赋值set<int>s3;s3 = s2;printSet(s3);
}int main()
{test01();system("pause");return 0;
}

输出结果:

10 20 30 40
10 20 30 40
10 20 30 40
请按任意键继续. . .

1.3set大小和交换

功能描述:统计set容器大小以及交换set容器

函数原型:

size();   //返回容器中元素的数目
empty();  //判断容器是否为空
swap(st); //交换两个集合容器
#include <iostream>
using namespace std;
#include<set>
//set容器大小和交换
//size();   //返回容器中元素的数目
//empty();  //判断容器是否为空
//swap(st); //交换两个集合容器
void printSet(set<int>& s)
{for (set<int>::const_iterator it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout << endl;
}void test01()
{//创建set容器set<int>s1;//默认构造//插入数据,只有insert方式s1.insert(10);s1.insert(40);s1.insert(30);s1.insert(20);s1.insert(30);//遍历容器//set容器特点:所有元素插入时自动被排序//set容器不允许插入重复值printSet(s1);//判断是否为空if (s1.empty()){cout << "s1为空" << endl;}else{cout << "s1不为空" << endl;cout << "s1的大小为:" << s1.size() << endl;}
}void test02()
{set<int>s1;//插入数据,只有insert方式s1.insert(10);s1.insert(30);s1.insert(20);s1.insert(40);set<int>s2;//插入数据,只有insert方式s2.insert(100);s2.insert(300);s2.insert(200);s2.insert(400);cout << "交换前:" << endl;printSet(s1);printSet(s2);//交换s1.swap(s2);cout << "交换后:" << endl;printSet(s1);printSet(s2);
}int main()
{test01();test02();system("pause");return 0;
}

 输出结果:

10 20 30 40
s1不为空
s1的大小为:4
交换前:
10 20 30 40
100 200 300 400
交换后:
100 200 300 400
10 20 30 40
请按任意键继续. . .

1.4set插入和删除

功能描述:set容器进行插入数据和删除数据

函数原型:

insert(elem);    //在容器中插入元素
clear();         //清除所有元素
erase(pos);      //删除pos迭代器所指的元素,返回下一个元素的迭代器
erase(beg, end); //删除区间[beg,end)的所有元素 ,返回下一个元素的迭代器
erase(elem);     //删除容器中值为elem的元素
#include <iostream>
using namespace std;
#include<set>
//set容器插入数据和删除数据
//insert(elem);    //在容器中插入元素
//clear();         //清除所有元素
//erase(pos);      //删除pos迭代器所指的元素,返回下一个元素的迭代器
//erase(beg, end); //删除区间[beg,end)的所有元素 ,返回下一个元素的迭代器
//erase(elem);     //删除容器中值为elem的元素
void printSet(set<int>& s)
{for (set<int>::const_iterator it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout << endl;
}void test01()
{//创建set容器set<int>s1;//默认构造//插入数据,只有insert方式s1.insert(30);s1.insert(10);s1.insert(20);s1.insert(40);//遍历容器//set容器特点:所有元素插入时自动被排序//set容器不允许插入重复值printSet(s1);//删除s1.erase(s1.begin());//因为排序了,所以是把10删除了printSet(s1);//删除重载版本s1.erase(30);printSet(s1);//清空//二者实现功能一致//s1.erase(s1.begin(), s1.end());s1.clear();printSet(s1);
}int main()
{test01();system("pause");return 0;
}

输出结果:

10 20 30 40
20 30 40
20 40请按任意键继续. . .

1.5set查找和统计

功能描述:对set容器进行查找数据以及统计数据
函数原型:

find(key); //查找key是否存在,若存在,返回该键的元素的选代器;若不存在,返回set.end();
count(key);//统计key的元素个数

注意:

set.end()是最后一个元素的下一位置,可以理解为空

对于set而言,count()的统计结果,要么是0,要么是1。因为set容器不允许插入重复值

#include <iostream>
using namespace std;
#include<set>
//set容器查找和统计
//find(key); //查找key是否存在,若存在,返回该键的元素的选代器;若不存在,返回set.end();
//count(key);//统计key的元素个数void test01()
{//创建set容器set<int>s1;//默认构造//插入数据,只有insert方式s1.insert(30);s1.insert(10);s1.insert(20);s1.insert(40);s1.insert(30);s1.insert(30);//遍历容器//set容器特点:所有元素插入时自动被排序//set容器不允许插入重复值set<int>::iterator pos = s1.find(40);if (pos == s1.end()){cout << "未找到元素!" << endl;}else{cout << "找到元素:" << *pos << endl;}//统计30的个数//对于set而言,统计结果,要么是0,要么是1int num = s1.count(30);cout << "num = " << num << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

找到元素:40
num = 1
请按任意键继续. . .

1.6set和multiset区别

学习目标:掌握set和multiset的区别

区别:

        set不可以插入重复数据,而multiset可以

        set插入数据的同时会返回插入结果,表示插入是否成功(返回的结果会以对组显示)

        multiset不会检测数据,因此可以插入重复数据

总结:

        如果不允许插入重复数据可以利用set

        如果需要插入重复数据利用multiset

#include <iostream>
using namespace std;
#include<set>
//set和multiset区别
void printSet(set<int>& s)
{for (set<int>::const_iterator it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout << endl;
}void test01()
{//创建set容器set<int>s1;//默认构造//插入数据,只有insert方式//返回值的对组,我们尝试接收一下//第一个值是个迭代器 第二个值是boolpair < set<int>::iterator, bool >ret = s1.insert(10);if (ret.second){cout << "第一次插入为真" << endl;}else{cout << "第一次插入为假" << endl;}//set容器不允许插入重复值ret = s1.insert(10);if (ret.second){cout << "第二次插入为真" << endl;}else{cout << "第二次插入为假" << endl;}multiset<int>ms;//允许插入重复值ms.insert(10);ms.insert(10);ms.insert(10);//遍历容器for (multiset<int>::iterator it = ms.begin(); it != ms.end(); it++){cout << *it << " ";}cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

第一次插入为真
第二次插入为假
10 10 10
请按任意键继续. . .

1.7pair对组创建

功能描述:成对出现的数据,利用对组可以返回两个数据

两种创建方式:

pair<type, type>p(value1, value2);
pair<type, type>p = make_pair(value1, value2);
#include <iostream>
using namespace std;
#include<string>
//pair对组创建
//两种创建方式 :
//pair<type, type>p(value1, value2);
//pair<type, type>p = make_pair(value1, value2);
void test01()
{//第一种方式pair<string, int>p("Tom", 20);cout << "姓名:" << p.first << "年龄:" << p.second << endl;//第二种方式pair<string, int>p2("jerry", 30);cout << "姓名:" << p2.first << "年龄:" << p2.second << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

姓名:Tom年龄:20
姓名:jerry年龄:30
请按任意键继续. . .

1.8set容器排序

学习目标:
        set容器默认排序规则为从小到大,掌握如何改变排序规则

主要技术点:
        利用仿函数,可以改变排序规则

#include <iostream>
using namespace std;
#include<set>
//set容器排序(内置数据类型)
class myCompare
{
public:bool operator()(int v1, int v2)const{return v1 > v2;}
};void test01()
{set<int>s1;s1.insert(10);s1.insert(40);s1.insert(20);s1.insert(50);s1.insert(30);for (set<int>::iterator it = s1.begin(); it != s1.end(); it++){cout << *it << " ";}cout << endl;//指定排序规则为从大到小set<int, myCompare>s2;s2.insert(10);s2.insert(40);s2.insert(20);s2.insert(50);s2.insert(30);for (set<int, myCompare>::iterator it = s2.begin(); it != s2.end(); it++){cout << *it << " ";}cout << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

10 20 30 40 50
50 40 30 20 10
请按任意键继续. . .
#include <iostream>
using namespace std;
#include<string>
#include<set>
//set容器排序(存放自定义数据类型)
class Person
{
public:Person(string name, int age){this->m_Name = name;this->m_Age = age;}string m_Name;int m_Age;
};class myComparePerson
{
public:bool operator()(const Person& p1, const Person& p2)const{//按照年龄降序return p1.m_Age > p2.m_Age;}
};void test01()
{//自定义数据类型,都会先指定排序规则set<Person, myComparePerson>s;//创建Person对象Person p1("刘备", 24);Person p2("关羽", 28);Person p3("张飞", 25);Person p4("赵云", 21);s.insert(p1);s.insert(p2);s.insert(p3);s.insert(p4);for (set<Person, myComparePerson>::const_iterator it = s.begin(); it != s.end(); it++){cout << "姓名:" << it->m_Name << "年龄:" << it->m_Age << endl;}
}int main()
{test01();system("pause");return 0;
}

输出结果:

姓名:关羽年龄:28
姓名:张飞年龄:25
姓名:刘备年龄:24
姓名:赵云年龄:21
请按任意键继续. . .

2、map / multimap容器

2.1map基本概念

简介:

map中所有元素都是pair(对组)

pair中第一个元素为key(键值),起到索引作用,第二个元素为value(实值)

所有元素都会根据元素的键值自动排序

本质:
map/multimap属于关联式容器,底层结构是用二叉树实现

优点:
可以根据key值快速找到value值

map和multimap区别:
map不允许容器中有重复key值元素
multimap允许容器中有重复key值元素

2.2map构造和赋值

功能描述:对map容器进行构造和赋值操作

函数原型:

//构造
map<T1,T2> mp;    //map默认构造函数
map(const map& mp);//拷贝构造函数
//赋值:
map& operator=(const map& mp);//重载等号操作符
#include <iostream>
using namespace std;
#include<map>
//map容器构造和赋值
//构造:
//map<T1,T2> mp;               //map默认构造函数
//map(const map& mp);           //拷贝构造函数
//赋值:
//map& operator=(const map& mp);//重载等号操作符
void printMap(map<int, int>& m)
{for (map<int, int>::iterator it = m.begin(); it != m.end(); it++){cout << "key = " << (*it).first << " value = " << it->second << endl;}cout << endl;
}void test01()
{//创建map容器map<int, int>m;m.insert(pair<int, int>(4, 40));m.insert(pair<int, int>(3, 30));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(1, 10));printMap(m);//拷贝构造map<int, int>m2(m);printMap(m2);//赋值map<int, int>m3;m3 = m2;printMap(m3);
}int main()
{test01();system("pause");return 0;
}

总结:map中所有元素都是成对出现的,插入数据时要使用对组 

输出结果:

key = 1 value = 10
key = 2 value = 20
key = 3 value = 30
key = 4 value = 40key = 1 value = 10
key = 2 value = 20
key = 3 value = 30
key = 4 value = 40key = 1 value = 10
key = 2 value = 20
key = 3 value = 30
key = 4 value = 40请按任意键继续. . .

2.3map大小和交换

功能描述:统计map容器大小以及交换map容器

函数原型:

size();   //返回容器中元素的数目
empty();  //判断容器是否为空
swap(st); //交换两个集合容器
#include <iostream>
using namespace std;
#include<map>
//map容器大小和交换
//size();   //返回容器中元素的数目
//empty();  //判断容器是否为空
//swap(st); //交换两个集合容器
void printMap(map<int, int>& m)
{for (map<int, int>::iterator it = m.begin(); it != m.end(); it++){cout << "key = " << (*it).first << " value = " << it->second << endl;}cout << endl;
}
//大小
void test01()
{//创建map容器map<int, int>m;  m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(3, 30));if (m.empty()){cout << "m为空" << endl;}else{cout << "m不为空" << endl;cout << "m的大小为:" << m.size() << endl;}
}
//交换
void test02()
{map<int, int>m;m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(3, 30));map<int, int>m2;m2.insert(pair<int, int>(4, 100));m2.insert(pair<int, int>(5, 200));m2.insert(pair<int, int>(6, 300));cout << "交换前:" << endl;printMap(m);printMap(m2);m.swap(m2);cout << "交换后:" << endl;printMap(m);printMap(m2);
}int main()
{test01();test02();system("pause");return 0;
}

输出结果:

m不为空
m的大小为:3
交换前:
key = 1 value = 10
key = 2 value = 20
key = 3 value = 30key = 4 value = 100
key = 5 value = 200
key = 6 value = 300交换后:
key = 4 value = 100
key = 5 value = 200
key = 6 value = 300key = 1 value = 10
key = 2 value = 20
key = 3 value = 30请按任意键继续. . .

2.4map插入和删除

功能描述:map容器进行插入数据和删除数据

函数原型:

insert(elem);    //在容器中插入元素
clear();         //清除所有元素
erase(pos);      //删除pos迭代器所指的元素,返回下一个元素的迭代器
erase(beg, end); //删除区间[beg,end)的所有元素,返回下一个元素的迭代器
erase(key);      //删除容器中值为key的元素
#include <iostream>
using namespace std;
#include<map>
//map容器插入数据和删除数据
//insert(elem);    //在容器中插入元素
//clear();         //清除所有元素
//erase(pos);      //删除pos迭代器所指的元素,返回下一个元素的迭代器
//erase(beg, end); //删除区间[beg,end)的所有元素,返回下一个元素的迭代器
//erase(key);      //删除容器中值为key的元素
void printMap(map<int, int>& m)
{for (map<int, int>::iterator it = m.begin(); it != m.end(); it++){cout << "key = " << (*it).first << " value = " << it->second << endl;}cout << endl;
}void test01()
{//创建map容器map<int, int>m;  //插入//第一种m.insert(pair<int, int>(1, 10));//第二种m.insert(make_pair(2, 20));//第三种m.insert(map<int, int>::value_type(3, 30));//第四种m[4] = 40;//[]不建议插入,用途 可以利用key访问到valuecout << m[4] << endl;printMap(m);//删除m.erase(m.begin());printMap(m);m.erase(3);//按照key删除printMap(m);//清空m.erase(m.begin(), m.end());//m.clear();  //二者等价printMap(m);
}int main()
{test01();system("pause");return 0;
}

输出结果:

40
key = 1 value = 10
key = 2 value = 20
key = 3 value = 30
key = 4 value = 40key = 2 value = 20
key = 3 value = 30
key = 4 value = 40key = 2 value = 20
key = 4 value = 40请按任意键继续. . .

 2.5map查找和统计

功能描述:对map容器进行查找数据以及统计数据

函数原型:

find(key); //查找key是否存在,若存在,返回该键的元素的迭代器;若不存在,返回set,end();
count(key);//统计key的元素个数
#include <iostream>
using namespace std;
#include<map>
//map容器查找数据以及统计数据
//find(key); //查找key是否存在,若存在,返回该键的元素的迭代器;若不存在,返回set,end();
//count(key);//统计key的元素个数
void test01()
{//查找//创建map容器map<int, int>m;  //插入数据m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(2, 20));m.insert(pair<int, int>(3, 30));map<int, int>::iterator pos = m.find(3);//返回值为迭代器if (pos != m.end()){cout << "查到了元素 key = " << (*pos).first << " value =" << pos->second << endl;}else{cout << "未找到元素" << endl;}//统计int num = m.count(3);//map不允许插入重复key元素,count统计值只能为0或1//multimap的count值可能大于1cout << "num = " << num << endl;
}int main()
{test01();system("pause");return 0;
}

输出结果:

查到了元素 key = 3 value =30
num = 1
请按任意键继续. . .

2.6map容器排序

学习目标:map容器默认排序规则为 按照key值进行 从小到大排序,掌握如何改变排序规则

主要技术点:利用仿函数,可以改变排序规则

#include <iostream>
using namespace std;
#include<map>
//map容器排序
void test01()
{//创建map容器map<int, int>m;  //插入数据m.insert(pair<int, int>(1, 10));m.insert(pair<int, int>(5, 50));m.insert(pair<int, int>(3, 30));m.insert(pair<int, int>(4, 40));m.insert(pair<int, int>(2, 20));for (map<int, int>::iterator it = m.begin(); it != m.end(); it++){cout << "key = " << (*it).first << " value = " << it->second << endl;}cout << endl;
}class MyCompare
{
public:bool operator()(int v1, int v2)const{//降序return v1 > v2;}
};void test02()
{//创建map容器map<int, int, MyCompare>m1;//插入数据m1.insert(pair<int, int>(1, 10));m1.insert(pair<int, int>(5, 50));m1.insert(pair<int, int>(3, 30));m1.insert(pair<int, int>(4, 40));m1.insert(pair<int, int>(2, 20));for (map<int, int, MyCompare>::iterator it = m1.begin(); it != m1.end(); it++){cout << "key = " << (*it).first << " value = " << it->second << endl;}cout << endl;
}int main()
{test01();test02();system("pause");return 0;
}

输出结果:

key = 1 value = 10
key = 2 value = 20
key = 3 value = 30
key = 4 value = 40
key = 5 value = 50key = 5 value = 50
key = 4 value = 40
key = 3 value = 30
key = 2 value = 20
key = 1 value = 10请按任意键继续. . .

3、STL案例---员工分组

案例描述:
公司今天招聘了10个员工(ABCDEFGHI),10名员工进入公司之后,需要指派员工在那个部门工作。员工信息有: 姓名 工资组成;部门分为:策划、美术、研发。随机给10名员工分配部门和工资。通过multimap进行信息的插入 key(部门编号) value(员工)。分部门显示员工信息

实现步骤:
1.创建10名员工,放到vector中
2.遍历vector容器,取出每个员工,进行随机分组
3.分组后,将员工部门编号作为key,具体员工作为value,放入到multimap容器中
4.分部门显示员工信息

#include <iostream>
using namespace std;
#include<vector>
#include<string>
#include<map>
#include<ctime>#define CEHUA  0
#define MEISHU 1
#define YANFA  2class Worker
{
public:string m_Name;int m_Salary;
};void creatWorker(vector<Worker>& v)
{string nameSeed = "ABCDEFGHIJ";for (int i = 0; i < 10; i++){Worker worker;worker.m_Name = "员工";worker.m_Name += nameSeed[i];worker.m_Salary = rand() % 10000 + 10000;//10000--19999//将员工放入到容器中v.push_back(worker);}
}
//员工分组
void setGroup(vector<Worker>& v, multimap<int, Worker>& m)
{for (vector<Worker>::iterator it = v.begin(); it != v.end(); it++){//产生随机部门编号int deptID = rand() % 3;//0 1 2//将员工插入到分组中//key部门编号,value具体员工m.insert(make_pair(deptID, *it));}
}void showWorkerByGroup(multimap<int, Worker>& m)
{//0   1    2cout << "策划部门:" << endl;multimap<int, Worker>::iterator pos = m.find(CEHUA);int count = m.count(CEHUA);//统计策划部门的人数int index = 0;for (; pos != m.end() && index < count; pos++, index++){cout << "姓名:" << pos->second.m_Name << "工资:" << pos->second.m_Salary << endl;}cout << "-----------------------------" << endl;cout << "美术部门:" << endl;pos = m.find(MEISHU);count = m.count(MEISHU);//统计美术部门的人数index = 0;for (; pos != m.end() && index < count; pos++, index++){cout << "姓名:" << pos->second.m_Name << "工资:" << pos->second.m_Salary << endl;}cout << "-----------------------------" << endl;cout << "研发部门:" << endl;pos = m.find(YANFA);count = m.count(YANFA);//统计美术部门的人数index = 0;for (; pos != m.end() && index < count; pos++, index++){cout << "姓名:" << pos->second.m_Name << "工资:" << pos->second.m_Salary << endl;}
}
int main()
{srand((unsigned int)time(NULL));//随机数种子//1、创建员工vector<Worker>vWorker;creatWorker(vWorker);//测试/*for (vector<Worker>::iterator it = vWorker.begin(); it != vWorker.end(); it++){cout << "姓名:" << it->m_Name << " 工资:" << it->m_Salary << endl;}*///2、员工分组multimap<int, Worker>mWorker;setGroup(vWorker, mWorker);//3、分组显示员工showWorkerByGroup(mWorker);system("pause");return 0;
}

输出结果(因为加入了随机数种子,每次结果都不一样):

策划部门:
姓名:员工B工资:12401
姓名:员工G工资:12710
姓名:员工H工资:11054
姓名:员工I工资:17756
姓名:员工J工资:13103
-----------------------------
美术部门:
姓名:员工A工资:12620
姓名:员工C工资:17687
姓名:员工D工资:16582
姓名:员工F工资:12674
-----------------------------
研发部门:
姓名:员工E工资:16102
请按任意键继续. . .

这篇关于C++提高笔记(五)---STL容器(set/multiset、map/multimap)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/817516

相关文章

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

深入解析C++ 中std::map内存管理

《深入解析C++中std::map内存管理》文章详解C++std::map内存管理,指出clear()仅删除元素可能不释放底层内存,建议用swap()与空map交换以彻底释放,针对指针类型需手动de... 目录1️、基本清空std::map2️、使用 swap 彻底释放内存3️、map 中存储指针类型的对象

C++ STL-string类底层实现过程

《C++STL-string类底层实现过程》本文实现了一个简易的string类,涵盖动态数组存储、深拷贝机制、迭代器支持、容量调整、字符串修改、运算符重载等功能,模拟标准string核心特性,重点强... 目录实现框架一、默认成员函数1.默认构造函数2.构造函数3.拷贝构造函数(重点)4.赋值运算符重载函数

C++ vector越界问题的完整解决方案

《C++vector越界问题的完整解决方案》在C++开发中,std::vector作为最常用的动态数组容器,其便捷性与性能优势使其成为处理可变长度数据的首选,然而,数组越界访问始终是威胁程序稳定性的... 目录引言一、vector越界的底层原理与危害1.1 越界访问的本质原因1.2 越界访问的实际危害二、基

Python学习笔记之getattr和hasattr用法示例详解

《Python学习笔记之getattr和hasattr用法示例详解》在Python中,hasattr()、getattr()和setattr()是一组内置函数,用于对对象的属性进行操作和查询,这篇文章... 目录1.getattr用法详解1.1 基本作用1.2 示例1.3 原理2.hasattr用法详解2.

c++日志库log4cplus快速入门小结

《c++日志库log4cplus快速入门小结》文章浏览阅读1.1w次,点赞9次,收藏44次。本文介绍Log4cplus,一种适用于C++的线程安全日志记录API,提供灵活的日志管理和配置控制。文章涵盖... 目录简介日志等级配置文件使用关于初始化使用示例总结参考资料简介log4j 用于Java,log4c

C++归并排序代码实现示例代码

《C++归并排序代码实现示例代码》归并排序将待排序数组分成两个子数组,分别对这两个子数组进行排序,然后将排序好的子数组合并,得到排序后的数组,:本文主要介绍C++归并排序代码实现的相关资料,需要的... 目录1 算法核心思想2 代码实现3 算法时间复杂度1 算法核心思想归并排序是一种高效的排序方式,需要用

C++11范围for初始化列表auto decltype详解

《C++11范围for初始化列表autodecltype详解》C++11引入auto类型推导、decltype类型推断、统一列表初始化、范围for循环及智能指针,提升代码简洁性、类型安全与资源管理效... 目录C++11新特性1. 自动类型推导auto1.1 基本语法2. decltype3. 列表初始化3

C++11右值引用与Lambda表达式的使用

《C++11右值引用与Lambda表达式的使用》C++11引入右值引用,实现移动语义提升性能,支持资源转移与完美转发;同时引入Lambda表达式,简化匿名函数定义,通过捕获列表和参数列表灵活处理变量... 目录C++11新特性右值引用和移动语义左值 / 右值常见的左值和右值移动语义移动构造函数移动复制运算符

C++中detach的作用、使用场景及注意事项

《C++中detach的作用、使用场景及注意事项》关于C++中的detach,它主要涉及多线程编程中的线程管理,理解detach的作用、使用场景以及注意事项,对于写出高效、安全的多线程程序至关重要,下... 目录一、什么是join()?它的作用是什么?类比一下:二、join()的作用总结三、join()怎么