función C ++ conjunto STL :: size () : Aquí, vamos a aprender acerca de la función size () del conjunto en C ++ STL (Standard Template Library).
C ++ STL set :: size () Función
set :: size () es una función predefinida, se usa para obtener el tamaño de un conjunto, devuelve el número total de elementos de la contenedor set.
Prototipo:
set<T> st; //declaration
set<T>::iterator it; //iterator declaration
int sz=st.size();
Parámetro: Nada pase a
class escribir: Entero
Uso: El tamaño devuelve la función del conjunto
Ejemplo:
For a set of integer,
set<int> st;
set<int>::iterator it;
st.insert(4);
st.insert(5);
set content:
4
5
int sz=st.size(); //sz=size of set that is 2
Print sz; //prints 2
archivo de cabecera que se incluirá:
#include <iostream>
#include <set>
OR
#include <bits/stdc++.h>
implementación en C ++:
#include <bits/stdc++.h>
using namespace std;
void printSet(set<int> st){
set<int>:: iterator it;
cout<<"Set contents are:n";
for(it=st.begin();it!=st.end();it++)
cout<<*it<<" ";
cout<<endl;
}
int main(){
cout<<"Example of size functionn";
set<int> st;
set<int>:: iterator it;
cout<<"inserting 4n";
st.insert(4);
cout<<"inserting 6n";
st.insert(6);
cout<<"inserting 10n";
st.insert(10);
printSet(st); //printing current set
//finding set sizeof
cout<<"current set size is: "<<st.size();
return 0;
}
salida
Example of size function
inserting 4
inserting 6
inserting 10
Set contents are:
4 6 10
current set size is: 3