Linux与Windows中map类erase方法的差异
来源:互联网 发布:北京好玩的地方 知乎 编辑:程序博客网 时间:2024/05/08 23:05
1 #include <iostream>
2 #include <map>
3 #include <string>
4
5 using namespace std;
6
7 int main(int argc, char* argv[])
8 {
9 map<string, int> MyMap;
10
11 MyMap["bujiwu"] = 26;
12 MyMap["swallow"] = 25;
13
14 std::cout <<"Before delete element:" << std::endl;
15 for( map<string, int>::iterator Itor = MyMap.begin();
16 Itor != MyMap.end(); Itor++ )
17 {
18 std::cout << Itor->first << " " << Itor->second << std::endl;
19 }
20
21 for( map<string, int>::iterator Itor = MyMap.begin();
22 Itor != MyMap.end(); )
23 {
24 if ( Itor->first == "bujiwu" )
25 {
26 MyMap.erase(Itor++); //在windows下也可以Itor = MyMap.erase(Itor),但是在linux下不行。
27 }
28 else
29 {
30 Itor++;
31 }
32 }
33
34 std::cout <<"After delete element:" << std::endl;
35 for( map<string, int>::iterator Itor = MyMap.begin();
36 Itor != MyMap.end(); Itor++ )
37 {
38 std::cout << Itor->first << " " << Itor->second << std::endl;
39 }
40
41 return 0;
42 }
43
44
2 #include <map>
3 #include <string>
4
5 using namespace std;
6
7 int main(int argc, char* argv[])
8 {
9 map<string, int> MyMap;
10
11 MyMap["bujiwu"] = 26;
12 MyMap["swallow"] = 25;
13
14 std::cout <<"Before delete element:" << std::endl;
15 for( map<string, int>::iterator Itor = MyMap.begin();
16 Itor != MyMap.end(); Itor++ )
17 {
18 std::cout << Itor->first << " " << Itor->second << std::endl;
19 }
20
21 for( map<string, int>::iterator Itor = MyMap.begin();
22 Itor != MyMap.end(); )
23 {
24 if ( Itor->first == "bujiwu" )
25 {
26 MyMap.erase(Itor++); //在windows下也可以Itor = MyMap.erase(Itor),但是在linux下不行。
27 }
28 else
29 {
30 Itor++;
31 }
32 }
33
34 std::cout <<"After delete element:" << std::endl;
35 for( map<string, int>::iterator Itor = MyMap.begin();
36 Itor != MyMap.end(); Itor++ )
37 {
38 std::cout << Itor->first << " " << Itor->second << std::endl;
39 }
40
41 return 0;
42 }
43
44
通过测试在不管在linux还是Windows平台下,vector,list都有方法iterator erase( iterator _Where );
但是在Linux下map中没有方法iterator erase( iterator _Where ); 所以上述代码在Linux平台下第26行必须写成MyMap.erase(Itor++),而不能写能Itor = MyMap.erase(Itor). 在Windows下二种方法都可以。
- Linux与Windows中map类erase方法的差异
- Linux与Windows中map类erase方法的差异
- Linux与Windows中map类erase方法的差异
- map类的erase方法的在Linux与Windows中的差异
- Linux与Windows中map类erase方法实现的不同决定使用的不同
- Windows与Linux编译器的差异
- Windows与Linux编译器的差异
- Linux与Windows系统的差异
- Linux与Windows文件系统的差异比较
- 关于map的erase方法的使用
- Windows和Linux中Sleep()的差异
- 正确运用stl map的erase方法
- 正确运用stl map的erase方法
- 正确运用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 正确使用stl map的erase方法
- 华为网络工程师基础教程
- 【Android】Layout 水平平分空间、垂直平分空间
- 无线上网技巧、天线制作(可免费上网)
- 电子电路大全(免费下载)
- 防止多用户登录 J2ee
- Linux与Windows中map类erase方法的差异
- django 中datetime.now()可能导致的错误
- sap 关于出先打印机选择窗口问题
- 35岁前务必成功的12级跳
- 计算机与网络技术
- 简介skyline
- 无线电基础
- 检测iphone设备是否越狱
- VB基础教程