C++ std::map Checking number of elements


The container std::map has a member function empty(), which returns true or false, depending on whether the map is empty or not. The member function size() returns the number of element stored in a std::map container:

std::map<std::string , int> rank {{"facebook.com", 1} ,{"google.com", 2}, {"youtube.com", 3}};
    std::cout << "Number of elements in the rank map: " << rank.size() << std::endl;
    std::cout << "The rank map is empty" << std::endl;