public member function
<locale>

std::ctype::scan_is

const char_type* scan_is (mask m, const char_type* low, const char_type* high) const;
返回類別中的第一個字元
在範圍 [low,high) 中返回分類到 m 中指定的任何類別的第一個字元。如果在該範圍內未找到此類字元,則返回 high

ctype 的泛型模板中,此函式僅呼叫虛保護成員 do_scan_is,該成員預設執行上述操作。

char 特化 (ctype<char>) 中,此函式使用內部 table 直接返回結果,而不呼叫任何虛成員。

引數

m
成員型別 mask 的位掩碼(從 ctype_base 繼承),指定要掃描的類別。如果位掩碼組合了多個類別,則函式將返回指向屬於任何類別的第一個字元的指標。
它可以是以下成員位掩碼值的任何按位組合
成員常量描述
spaceunspecified (unique bits)空白字元
printunspecified (unique bits)可列印字元
cntrlunspecified (unique bits)控制字元
upperunspecified (unique bits)大寫字母
lowerunspecified (unique bits)小寫字母
alphaunspecified (unique bits)字母字元
digitunspecified (unique bits)十進位制數字
punctunspecified (unique bits)標點符號字元
xdigitunspecified (unique bits)十六進位制數字
alnumalpha|digit字母數字字元
graphalnum|punct具有圖形表示的字元
成員常量描述
spaceunspecified (unique bits)空白字元
printunspecified (unique bits)可列印字元
cntrlunspecified (unique bits)控制字元
upperunspecified (unique bits)大寫字母
lowerunspecified (unique bits)小寫字母
alphaunspecified (unique bits)字母字元
digitunspecified (unique bits)十進位制數字
punctunspecified (unique bits)標點符號字元
xdigitunspecified (unique bits)十六進位制數字
blankunspecified (unique bits)空白字元
alnumalpha|digit字母數字字元
graphalnum|punct具有圖形表示的字元
有關 ASCII 字元如何根據這些類別進行分類的詳細資訊,請參閱 <cctype>
low, high
指向字元序列的開始和結束的指標。使用的範圍是 [low,high),它包含 lowhigh 之間的所有字元,包括 low 指向的字元,但不包括 high 指向的字元。
請注意,空字元(如果有)也會被考慮在內,並且函式會繼續遍歷它們,直到找到匹配項或完成整個範圍。
成員型別 char_type 是字面量的字元型別(定義為 ctype 的模板引數 charT 的別名)。

返回值

指向範圍內第一個分類的元素的指標,如果未找到,則為 high
成員型別 char_type 是字面量的字元型別(定義為 ctype 的模板引數 charT 的別名)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// ctype::scan_is example
#include <iostream>       // std::cout
#include <locale>         // std::locale, std::ctype, std::use_facet

int main ()
{
  std::locale loc;

  const char quote[] = "Characters do not change. Opinions alter, but characters are only developed.";
                       // (quoting Benjamin Disraeli)

  // get a pointer to the first "punctuation" character:
  const char * p = std::use_facet< std::ctype<char> >(loc).scan_is ( std::ctype<char>::punct, quote, quote+76 );

  std::cout << "The second sentence is: " << p << '\n';

  return 0;
}

輸出

The second sentence is: . Opinions alter, but characters are only developed.


資料競爭

物件以及範圍 [low,high) 中的元素會被訪問。

異常安全

強保證:如果丟擲異常,物件將不發生任何更改。

另見