Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ฟังก์ชัน unordered_multimap::size() ใน C++ STL

ฟังก์ชัน unordered_multimap::size() ใน C++ STL คืนค่าจำนวนสมาชิกใน Unordered Map

อัลกอริทึม

Begin
    Declare empty map container m
    Reserve bucket count
    Insert values into map
    Print size using size() function
End

โค้ดตัวอย่าง

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
    unordered_map<char, int> m; // empty map container
    m.reserve(6); // restrict bucket count
    m.insert(pair<char, int>('b', 10));
    m.insert(pair<char, int>('a', 20));
    cout << "The size is: " << m.size(); // print size
    return 0;
}

ผลลัพธ์

The size is: 2