Checking number of elements

suggest change

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}};
if(!rank.empty()){
    std::cout << "Number of elements in the rank map: " << rank.size() << std::endl;
} else {
    std::cout << "The rank map is empty" << std::endl;
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents