function template
<locale>

std::isxdigit

template <class charT>  bool isxdigit (charT c, const locale& loc);
使用 locale 檢查字元是否為十六進位制數字
該函式模板使用 locale 的 ctype 屬性檢查 c 是否為十六進位制數字字元,返回的結果與呼叫 ctype::is 相同,方式如下:

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

此函式模板過載了 C 語言函式 isxdigit(定義於 <cctype>)。

引數

c
要檢查的字元。
loc
要使用的 locale。它必須具有 ctype 方面。

模板引數 charT 是字元型別。

返回值

如果 c 確實是十六進位制數字字元,則返回 true
否則返回 false

示例

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

int main ()
{
  std::locale loc;
  std::string str="ffff";
  if ( std::isxdigit(str[0],loc) )
  {
    int number;
    std::stringstream(str) >> std::hex >> number;
    std::cout << "The hexadecimal number " << std::hex << number;
    std::cout << " is " << std::dec << number << ".\n";
  }
  return 0;
}

輸出

The hexadecimal number ffff is 65535.


資料競爭

將訪問 loc 及其 ctype 方面。

異常安全

強保證:如果丟擲異常,則沒有效果。

另見