A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_set_size.htm below:

C++ Set Library - size Function

C++ Set Library - size Function Description

It returns the number of elements in the set container.

Declaration

Following are the ways in which std::set::size works in various C++ versions.

C++98
size_type size() const;
C++11
size_type size() const noexcept;;
Return value

It returns the number of elements in the set container.

Exceptions

It never throws exceptions.

Time complexity

Time complexity is contstant.

Example

The following example shows the usage of std::set::size.

#include <iostream>
#include <set>

int main () {
   std::set<int> myints;
   std::cout << "0. size: " << myints.size() << '\n';

   for (int i = 0; i < 5; ++i) myints.insert(i);
   std::cout << "1. size: " << myints.size() << '\n';

   myints.insert (200);
   std::cout << "2. size: " << myints.size() << '\n';

   myints.erase(10);
   std::cout << "3. size: " << myints.size() << '\n';

   return 0;
}

The above program will compile and execute properly.

0. size: 0
1. size: 5
2. size: 6
3. size: 6

set.htm


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4