| 1 |
#include <algorithm> |
| 2 |
#include <iterator> |
| 3 |
#include <functional> |
| 4 |
#include <iostream> |
| 5 |
#include <string> |
| 6 |
#include <cstring> |
| 7 |
#include "predicates.h" |
| 8 |
using namespace std; |
| 9 |
|
| 10 |
int main(int argc, char **argv) |
| 11 |
{ |
| 12 |
if (argc == 1) |
| 13 |
cout << "Counted " << |
| 14 |
count_if(istream_iterator<char>(cin), istream_iterator<char>(), |
| 15 |
PredicateFunction1<char>(isdigit)) << " digits\n"; |
| 16 |
else |
| 17 |
cout << "Counted " << |
| 18 |
count_if(istream_iterator<char>(cin), istream_iterator<char>(), |
| 19 |
bind1st( |
| 20 |
PredicateFunction2<char const *, char, |
| 21 |
char const *(*)(char const *, int)>(strchr), |
| 22 |
"0123456789") |
| 23 |
) << " digits\n"; |
| 24 |
} |
| 25 |
/* |
| 26 |
Generated output after |
| 27 |
|
| 28 |
echo 1 world, there are 6 continents and 3 oceans | a.out |
| 29 |
or: |
| 30 |
echo 1 world, there are 6 continents and 3 oceans | a.out 2 |
| 31 |
|
| 32 |
Counted 3 digits |
| 33 |
*/ |