Namespaces
Variants

std::ctype <char> :: scan_not

From cppreference.net
定义于头文件 <locale>
const char * scan_not ( mask m, const char * beg, const char * end ) const ;

定位字符数组 [ beg , end ) 中首个不满足分类掩码 m 的字符,即首个使 table ( ) [ ( unsigned char ) c ] & m 返回 false 的字符 c

如果 ( unsigned char ) c >= std:: ctype < char > :: table_size ,则将使用实现定义的值替代 table ( ) [ ( unsigned char ) c ] ,该值可能因 c 的不同而不同。

目录

参数

m - 要搜索的掩码
beg - 指向待搜索字符数组中首个字符的指针
end - 指向待搜索字符数组结束位置后一位的指针

返回值

指向 [ beg , end ) 范围内首个不满足掩码条件的字符的指针,若未找到此类字符则返回 end

注释

与主模板 std:: ctype 不同,此特化版本在字符分类时不会执行虚函数调用。要自定义行为,派生类可以向基类构造函数提供非默认的分类表。

示例

#include <iostream>
#include <iterator>
#include <locale>
int main()
{
    auto& f = std::use_facet<std::ctype<char>>(std::locale());
    // 跳过前导空白字符
    char s1[] = "      \t\t\n  Test";
    const char* p1 = f.scan_not(std::ctype_base::space, std::begin(s1), std::end(s1));
    std::cout << '\'' << p1 << "'\n";
    // 跳过前导数字
    char s2[] = "123456789abcd";
    const char* p2 = f.scan_not(std::ctype_base::digit, std::begin(s2), std::end(s2));
    std::cout << '\'' << p2 << "'\n";
}

输出:

'Test'
'abcd'

参见

[virtual]
定位序列中首个不符合给定分类要求的字符
( std::ctype<CharT> 的虚受保护成员函数)
使用分类表定位序列中首个符合给定分类要求的字符
(公开成员函数)