当前位置:网站首页>Usage record of map < qstring, bool >
Usage record of map < qstring, bool >
2022-04-23 11:20:00 【Brother dampness】
My application examples are as follows :
map<QString, bool> m_allSkakFilepath;
auto itpath = m_allSkakFilepath.find(skaPaths.at(n).c_str());
if (itpath !=m_allSkakFilepath.end())
{
m_allSkakFilepath[skaPaths.at(n).c_str()] = false;
}
else
{
m_allSkakFilepath[skaPaths.at(n).c_str()] = true;
}
this map Main applications :
Usually there are many documents . And you need to find out whether the file is valid , Or used , If used, the flag bit is used as true, It can also be used to determine whether many components have been used , In short, no matter on any occasion , Just for the convenience of searching
The above code is to add or delete ,map Are the benefits of , Mainly above key It's not worth it map in , If you give the value directly, you will increase one key value
Here is another code for traversing the deletion , The following code is to delete map The median is true, Combined with the meaning of the above paragraph, it means that all the used values are cleared. Remember to clear them iter++:
map<QString, bool>::iterator iter=m_allSkakFilepath.begin();
for(;iter!=m_allSkakFilepath.end();){
if((*iter).second==true){
m_allSkakFilepath.erase(iter++);
}
else{
++iter;
}
}
map Clean up of :
// Clearing method 1: Direct will map Deleted
m_allSkakFilepath.clear();
//map.clear() Just put map It's empty , But the memory is not released , If you want to free memory, you need more than clear() fall , And an empty map To carry out swap, Free up memory
// Be careful map If the element is not a basic type , Also release the memory , Like a pointer ,vector Pay special attention to , otherwise map Takes up too much memory , Will cause the program to crash
// Clearing method 2 use map.erase(map.begin(),map.end()) better Empty elements
m_allSkakFilepath.erase(m_allSkakFilepath.begin(),m_allSkakFilepath.end());
// Clearing method 3
map<QString, bool> empty_map1;
m_allSkakFilepath.swap(empty_map1);
Output map size
Output map size
int nsize=m_allSkakFilepath.size();
map Sorting instructions for :map It defaults to key Sort values in ascending order , Personally, I think it's enough
If you want to traverse in reverse order ( use reverse_iterator The pointer ):
for( map<QString, bool>::reverse_iterator rit=m_allSkakFilepath.rbegin();rit!=m_allSkakFilepath.rend();rit++)
cout<<(*rit).first<<","<<(*rit).second<<endl;
modify map The value in , It's easy to change , As long as the key Set it to the corresponding value , as follows : Set up directly key3 from false become true
map<QString, bool> m_allSkakFilepath;
m_allSkakFilepath.insert(("key1", false));
m_allSkakFilepath.insert(("key2", false));
m_allSkakFilepath.insert(("key3", false));
m_allSkakFilepath.insert(("key4", true));
{
map<QString, bool>::const_iterator iteMap = m_allSkakFilepath.begin();
cout << "============== Old value result output =============" << endl;
for(; iteMap != m_allSkakFilepath.end(); ++ iteMap)
{
cout << m_allSkakFilepath->first;
cout << ":";
cout << m_allSkakFilepath->second << endl;
}
}
// modify
m_allSkakFilepath.insert(("key3", true));
{
map<QString, bool>::const_iterator iteMap = m_allSkakFilepath.begin();
cout << "============== New value result output =============" << endl;
for(; iteMap != m_allSkakFilepath.end(); ++ iteMap)
{
cout << m_allSkakFilepath->first;
cout << ":";
cout << m_allSkakFilepath->second << endl;
}
}
版权声明
本文为[Brother dampness]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231115090820.html
边栏推荐
- Pytorch neural network trainer
- PyTorch 神经网络训练器
- Upgrade the functions available for cpolar intranet penetration
- On lambda powertools typescript
- Which company is good for opening futures accounts? Who can recommend several safe and reliable futures companies?
- R-Drop:更强大的Dropout正则方法
- Mysql系列SQL查询语句书写顺序及执行顺序详解
- MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video
- 学习 Go 语言 0x06:《Go 语言之旅》中 斐波纳契闭包 练习题代码
- qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
猜你喜欢

Excel · VBA array bubble sorting function

Excel · VBA custom function to obtain multiple cell values

升级cpolar内网穿透能获得的功能

Get things technology network optimization - CDN resource request Optimization Practice

Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)

About the three commonly used auxiliary classes of JUC

Résumé de la relation entre GPU, cuda et cudnn

SVN的使用:

qt 64位静态版本显示gif

Jupyter Lab 十大高生产力插件
随机推荐
nacos基础(7):配置管理
Oracle连通性测试小工具
Excel·VBA数组冒泡排序函数
Difference between pregnancy box and delivery box
Detailed explanation of how to smoothly go online after MySQL table splitting
FileProvider 路径配置策略的理解
MySQL数据库事务transaction示例讲解教程
PDMS软光刻加工过程
MySQL8. 0 upgraded stepping on the pit Adventure
积极参与中学机器人竞赛的意义
Get things technology network optimization - CDN resource request Optimization Practice
Excel · VBA custom function to obtain multiple cell values
采用百度飞桨EasyDL完成指定目标识别
Write console script by laravel
升级cpolar内网穿透能获得的功能
详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
创客教育中的统筹方案管理模式
More reliable model art than deep learning
Solve the problem of "suncertpathbuilderexception: unable to find valid certification path to requested target"
MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了