VOOZH about

URL: https://www.geeksforgeeks.org/cpp/setsize-c-stl/

⇱ set::size() in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

set::size() in C++ STL

Last Updated : 4 Nov, 2024

In C++, set::size() function is a built-in used to find the number of elements in the given set container. It is the member function of std::set class defined inside <set> header file. In this article, we will learn about the std::set::size() method in C++.

Example:


Output
3

Syntax of set::size()

s.size();

Parameters

  • This function does not require any parameter.

Return Value

  • Returns the number of elements in the std::set container.
  • If the set is empty, it returns 0.

More Examples of set::size()

The following examples demonstrates the use of set::size() function in different scenarios:

Example 1: Find the Size of Set Container


Output
5
4

Example 2: Find the Size of Empty Set


Output
0
Comment
Article Tags: