当前位置:网站首页>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
边栏推荐
- stylecloud ,wordcloud 库学习及使用例子
- oh-my-lotto
- CUMCM 2021-B:乙醇偶合制备C4烯烃(2)
- mysql中整数数据类型tinyint详解
- 分享两个实用的shell脚本
- 解读机器人编程课程的生物认知度
- MySQL8.0升级的踩坑历险记
- 解读2022机器人教育产业分析报告
- 学习 Go 语言 0x08:《Go 语言之旅》中 练习使用 error
- 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
猜你喜欢
随机推荐
MySQL面试题讲解之如何设置Hash索引
Detailed explanation of how to smoothly go online after MySQL table splitting
FileProvider 路径配置策略的理解
解析幼儿教育中steam教育的融合
赛微微电科创板上市破发:跌幅达26% 公司市值44亿
Learn go language 0x03: understand the dependency between variables and initialization order
Learning website materials
语雀文档编辑器将开源:始于但不止于Markdown
Mysql8.0安装指南
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
Microsoft Access database using PHP PDO ODBC sample
oh-my-lotto
Upgrade the functions available for cpolar intranet penetration
Summary of QT semaphore unresolved errors
Canvas详解
PyTorch 神经网络训练器
26. Delete duplicates in ordered array
Structure of C language (Advanced)
Go interface usage
mysql创建存储过程及函数详解








