>i want to find out the number of lowercase letters used in the name...
The easy way:
Code:
#include <iostream>
#include <algorithm>
#include <cctype>
int main()
{
std::string name = "Julienne";
std::cout<< std::count_if ( name.begin(), name.end(), islower ) <<'\n';
}
The safe easy way:
Code:
#include <iostream>
#include <algorithm>
#include <cctype>
struct is_lower {
int operator() ( int c )
{
return islower ( c );
}
};
int main()
{
std::string name = "Julienne";
std::cout<< std::count_if ( name.begin(), name.end(), is_lower() ) <<'\n';
}
Why does the safe version put a seemingly unnecessary wrapper around islower? Because cctype declares a one argument version of islower, but iostream also declares a two argument version for use with locales. By passing just the name islower, which is overloaded in two headers that are both included, this creates an ambiguity that could cause problems for you. So a unique wrapper is used to call the single argument version and ensure that everything plays nicely. That said, the easy way works just peachy on a lot of compilers.