function template
<locale>
std::ispunct
template <class charT>
  bool ispunct (charT c, const locale& loc);
Check if character is a punctuation character using locale
Checks whether c is a punctuation 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::punct, c)
  |  | 
 
This function template overloads the C function ispunct (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 a punctuation character.
false otherwise.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
  | 
// ispunct example (C++)
#include <iostream>       // std::cout
#include <string>         // std::string
#include <locale>         // std::locale, std::ispunct
int main ()
{
  std::locale loc;
  std::string str="Hello, welcome!";
  int cx = 0;
  for (std::string::iterator it = str.begin(); it!=str.end(); ++it)
    if ( std::ispunct(*it,loc) ) ++cx;
  std::cout << "The sentence contains " << cx << " punctuation characters.\n";
  return 0;
}
  |  | 
 
Output:
The sentence contains 2 punctuation characters.
  | 
 
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
)
 
- ispunct (cctype)
 - Check if character is a punctuation character (function
)
 
- isgraph
 - Check if character has graphical representation using locale (function template
)
 
- iscntrl
 - Check if character is a control character using locale (function template
)