2019/c++

maps STL

fw93 2018. 3. 25. 22:03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main() {
    unordered_multimap<int, int> yeah;
    multimap<int, int> test3;
    // test3[1] = 2; 불가능
    //test3.insert(pair<int, int>(1, 2));
    test3.insert(pair<int, int>(1, 3));
    test3.insert(pair<int, int>(1, 4));
    test3.insert(pair<int, int>(1, 5));
    test3.insert(pair<int, int>(1, 2));
    cout << (*test3.find(1)).second << endl;
    cout << (*test3.begin()).second << endl;
    unordered_map<int, int> test2;
    test2[1] = 1;
    test2[2] = 2;
    test2[3] = 3;
    cout << test2[2] << endl;
    map<int, int> test;
    test[1] = 2;
    test[2] = 3;
    test[3] = 4;
    cout << test[2] << endl;
    while (1) {}
    return 0;
}
cs



sets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int main() {
    unordered_set<int> test;
    test.insert(5);
    test.insert(4);
    test.insert(3);
    test.insert(2);
    test.insert(1);
    //unordered_set<int>::iterator it2 = test.begin() + 4; 덧셈 안됨.
    for (unordered_set<int>::iterator it = test.begin(); it != test.end(); it++) {
        cout << *it << endl;
    }
    unordered_multiset<int> sma;
    sma.insert(1);
    sma.insert(2);
    sma.insert(5);
    sma.insert(5);
    sma.insert(1);
    for (unordered_multiset<int>::iterator it = sma.begin(); it != sma.end(); it++) {
        cout << *it << endl;
    }
    while (1) {}
    return 0;
}
cs


'2019 > c++' 카테고리의 다른 글

STL Queues  (0) 2018.03.28
SORTING  (0) 2018.03.26
variables and memory, declaration  (0) 2018.03.24
list inserts and deletes  (0) 2018.03.24
string manipulations ( pointers )  (0) 2018.03.22