Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
Miscellaneous
complex
exception
functional
iterator
limits
locale
memory
new
numeric
stdexcept
typeinfo
utility
valarray
locale
has_facet
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
locale
tolower
toupper
use_facet
standard facets:
codecvt
codecvt_base
codecvt_byname
collate
collate_byname
ctype
ctype_base
ctype_byname
messages
messages_base
messages_byname
moneypunct
moneypunct_byname
money_base
money_get
money_put
numpunct
numpunct_byname
num_get
num_put
time_base
time_get
time_get_byname
time_put
time_put_byname


isdigit

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

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


This function replicates the functionality of its C-library equivalent isdigit. See isdigit 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 decimal digit character, false otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// isdigit example (C++)
#include <iostream>
#include <string>
#include <sstream>
#include <locale>
using namespace std;
int main ()
{
  locale loc;
  string str="1776ad";
  if ( isdigit(str[0],loc) )
  {
    int year;
    stringstream(str) >> year;
    cout << "The year that followed " << year << " was " << (year+1) << ".\n";
  }
  return 0;
}


Output:

The year that followed 1776 was 1777.

See also