For Programmers: Free Programming Magazines  


Home > Archive > VC STL > August 2005 > How to count the element of a Set?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to count the element of a Set?
Davy

2005-08-19, 4:23 pm

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?


Kyle

2005-08-19, 4:23 pm

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
>

Arnie

2005-08-19, 4:23 pm

"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
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com