ispunct


function template
<locale>
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 ctype facet of locale loc, returning the same as a call to:

 
use_facet < ctype<charT> > (loc).is (ctype_base::punct, c)


This function replicates the functionality of its C-library equivalent ispunct. See ispunct for more info.

Parameters

c
Character to be checked.
loc
Locale to be used. Shall have facet ctype present.


Template parameter 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
16
// ispunct example (C++)
#include <iostream>
#include <string>
#include <locale>
using namespace std;

int main ()
{
  locale loc;
  string str="Hello, welcome!";
  int cx = 0;
  for (string::iterator it = str.begin(); it!=str.end(); ++it)
    if ( ispunct(*it,loc) ) ++cx;
  cout << "Sentence contains " << cx << " punctuation characters.\n";
  return 0;
}


Output:

Sentence contains 2 punctuation characters.


See also

isgraph