function template
<locale>

std::isdigit

template <class charT>  bool isdigit (charT c, const locale& loc);
Check if character is a decimal digit using locale
Checks whether c is a decimal digit character using the ctype facet of locale loc, returning the same as if ctype::is is called as:

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

This function template overloads the C function isdigit (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 decimal digit character.
false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// isdigit example (C++)
#include <iostream>       // std::cout
#include <string>         // std::string
#include <locale>         // std::locale, std::isdigit
#include <sstream>        // std::stringstream

int main ()
{
  std::locale loc;
  std::string str="1776ad";
  if (isdigit(str[0],loc))
  {
    int year;
    std::stringstream(str) >> year;
    std::cout << "The year that followed " << year << " was " << (year+1) << ".\n";
  }
  return 0;
}

Output:

The year that followed 1776 was 1777.


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