function template
<locale>
std::isalpha
template <class charT>
bool isalpha (charT c, const locale& loc);
Check if character is alphabetic using locale
Checks whether c is an alphabetic character using the ctype facet of locale loc, returning the same as if ctype::is is called as:
|
use_facet < ctype<charT> > (loc).is (ctype_base::alpha, c)
|
This function template overloads the C function isalpha (defined in <cctype>).
Parameters
- c
- Character to be checked.
- loc
- Locale to be used. It shall have a ctype facet.
The template argument charT is the character type.
Return Value
true
if indeed c is an alphabetic character.
false
otherwise.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// isalpha example (C++)
#include <iostream> // std::cout
#include <string> // std::string
#include <locale> // std::locale, std::isalpha
int main ()
{
std::locale loc;
std::string str="C++";
for (std::string::iterator it=str.begin(); it!=str.end(); ++it)
{
if (std::isalpha(*it,loc))
std::cout << "character " << *it << " is alphabetic\n";
else
std::cout << "character " << *it << " is not alphabetic\n";
}
return 0;
}
|
Output:
character C is alphabetic
character + is not alphabetic
character + is not alphabetic
|
Data races
Both loc and its ctype facet are accessed.
Exception safety
Strong guarantee: if an exception is thrown, there are no effects.
See also
- ctype
- Character type facet (class template
)
- isalpha (cctype)
- Check if character is alphabetic (function
)
- isalnum
- Check if character is alphanumeric using locale (function template
)
- isdigit
- Check if character is a decimal digit using locale (function template
)