Namespaces
Variants

std:: wcscspn

From cppreference.net
定义于头文件 <cwchar>
std:: size_t wcscspn ( const wchar_t * dest, const wchar_t * src ) ;

返回由 dest 指向的宽字符串的最大初始段长度,该段仅包含 出现在由 src 指向的宽字符串中的字符。

目录

参数

dest - 指向待分析的空终止宽字符串的指针
src - 指向包含待搜索字符的空终止宽字符串的指针

返回值

最大初始段的长度,该段仅包含在由 src 所指向的字符串中未出现的字符。

示例

以下输出是使用 clang (libc++) 获得的。

#include <cwchar>
#include <iostream>
#include <locale>
int main()
{
    wchar_t dest[] = L"白猫 黑狗 甲虫";
    //                      └───┐
    const wchar_t* src = L"甲虫,黑狗";
    const std::size_t len = std::wcscspn(dest, src);
    dest[len] = L'\0'; // terminates the segment to print it out
    std::wcout.imbue(std::locale("en_US.utf8"));
    std::wcout << L"The length of maximum initial segment is " << len << L".\n";
    std::wcout << L"The segment is \"" << dest << L"\".\n";
}

可能的输出:

The length of maximum initial segment is 3.
The segment is "白猫 ".

参见

返回仅由另一宽字符串中找到的宽字符组成的最大初始段长度
(函数)
在另一宽字符串中查找任一宽字符的首次出现位置
(function)
C 文档 for wcscspn