| Author |
How to count the element of a Set?
|
|
|
| Hello all,
I use
//----------------
set<int> set_int;
set<int>::iterator it;
for(it=set_int.begin();it!=set_int.end();it++){
counter++
}
//----------------
to count the element of a Set.
Is there any better count methods?
Best regards,
Davy
| |
| David D 2005-08-19, 4:23 pm |
| How about
counter=set_int.size();
/David
Davy wrote:
> Hello all,
>
> I use
> //----------------
> set<int> set_int;
> set<int>::iterator it;
> for(it=set_int.begin();it!=set_int.end();it++){
> counter++
> }
> //----------------
> to count the element of a Set.
>
> Is there any better count methods?
>
> Best regards,
> Davy
>
| |
| Duane Hebert 2005-08-19, 4:23 pm |
|
"Davy" <zhushenli@gmail.com> wrote in message news:1124454210.575814.56300@g49g2000cwa.googlegroups.com...
> //----------------
> set<int> set_int;
> set<int>::iterator it;
> for(it=set_int.begin();it!=set_int.end();it++){
> counter++
> }
> //----------------
> to count the element of a Set.
>
> Is there any better count methods?
Does std::set::size() not do what you want?
| |
|
| Davy wrote:
> Hello all,
>
> I use
> //----------------
> set<int> set_int;
> set<int>::iterator it;
> for(it=set_int.begin();it!=set_int.end();it++){
> counter++
> }
> //----------------
> to count the element of a Set.
>
> Is there any better count methods?
set_int.size();
>
> Best regards,
> Davy
>
| |
|
| "Davy" <zhushenli@gmail.com> wrote in message
news:1124454210.575814.56300@g49g2000cwa.googlegroups.com...
> Hello all,
>
> I use
> //----------------
> set<int> set_int;
> set<int>::iterator it;
> for(it=set_int.begin();it!=set_int.end();it++){
> counter++
> }
> //----------------
> to count the element of a Set.
>
> Is there any better count methods?
>
> Best regards,
> Davy
size_t set_size = set_int.size() ?
- Arnie
| |
| Bill Gates 2005-08-23, 3:58 am |
| all the containers provided by STL can tell the number of elements by member
methord size().
"Davy" <zhushenli@gmail.com>
??????:1124454210.575814.56300@g49g2000cwa.googlegroups.com...
> Hello all,
>
> I use
> //----------------
> set<int> set_int;
> set<int>::iterator it;
> for(it=set_int.begin();it!=set_int.end();it++){
> counter++
> }
> //----------------
> to count the element of a Set.
>
> Is there any better count methods?
>
> Best regards,
> Davy
>
|
|
|
|