count [C++ Reference]
Keywords: stl,set,count
Date: 2009-10-09T05:57:49-0700

[[count]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## count

Syntax:

        #include <set>
        size_type count( const key_type& key ) const;

The function count() returns the number of occurrences of key in the set, which is always 0 or 1. count() should run in logarithmic time.

For example, the following code uses count() to determine if elements are contained in the set:

         // Create a set of characters
         set<char> charSet;
         const char* s = "Hello There";
         for( int i=0; i < strlen(s); i++ ) {
           charSet.insert( s[i] );
         }
         // Display the set
         cout << charSet.count('A');
         cout << charSet.count('T');
         // output is "01" (the characters in the set are " HTehlor")

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •