-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathc11_for.cpp
135 lines (101 loc) · 2.04 KB
/
c11_for.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* =====================================================================================
*
* Filename: for.cpp
*
* Description:
*
* Version: 1.0
* Created: 2015年06月19日 11时01分17秒
* Revision: none
* Compiler: gcc
*
* Author: zt (),
* Organization:
*
* =====================================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
std::map<int, int> a =
{
{1, 100},
#if 0
{2, 200},
{3, 300},
{4, 400},
{9, 400},
#endif
};
int arr[] =
{ 2, 1, 4, 5, 5, 6};
std::vector<int> vec = { 1, 2 };
int main ( int argc, char* argv[] )
{
( void ) argc;
( void ) argv;
auto iter2 = a.begin();
for ( auto iter = a.begin(); iter != a.end(); )
{
printf ( "size=%ld ", a.size() );
if ( iter->first == 1 )
iter2 = a.erase ( iter++ );
else
++iter;
printf ( "size=%ld ", a.size() );
}
iter2 = a.begin();
printf ( "second =%d \n", iter2->second );
printf ( "second =%d \n", iter2->second );
printf ( "second =%d \n", iter2->second );
for ( auto ele : a )
{
printf ( "%d\n", ele.first );
}
#if 0
for ( auto& ele : a )
{
printf ( "| %d %d | %ld\n", ele.first, ele.second, a.size() );
if ( ele.first == 1 )
a.erase ( ele.first );
//a.insert ( std::pair<int, int> ( 9, 250 ) );
}
printf ( "\n" );
#endif
#if 0
for ( auto ele : vec )
{
printf ( "%d\n", ele );
}
auto& b = a;
for ( const auto& ele : b )
{
if ( ele.first == 3 )
b.erase ( ele.first );
printf ( "size=%ld\n", b.size() );
}
for ( const auto& ele : a )
{
printf ( "| %d %d | ", ele.first, ele.second );
}
printf ( "\n" );
#endif
#if 0
for ( const auto& ele : a )
{
printf ( "| %d %d | ", ele.first, ele.second );
}
printf ( "\n" );
for ( auto i : arr )
{
printf ( " %d ", i );
}
printf ( "\n" );
#endif
return 0;
}