Namespaces
Variants

std:: wcsspn

From cppreference.net
ヘッダーで定義 <cwchar>
size_t wcsspn ( const wchar_t * dest, const wchar_t * src ) ;

dest が指すワイド文字列の先頭部分で、 src が指すワイド文字列に含まれる文字のみで構成される最大のセグメントの長さを返します。

目次

パラメータ

dest - 解析対象のヌル終端ワイド文字列へのポインタ
src - 検索対象の文字を含むヌル終端ワイド文字列へのポインタ

戻り値

src が指すワイド文字列からのみの文字を含む最大初期セグメントの長さ。

#include <cwchar>
#include <iostream>
#include <locale>
int main()
{
    wchar_t dest[] = L"白猫 黑狗 甲虫";
    const wchar_t src[] = L" 狗猫 白黑 ";
    const std::size_t len = std::wcsspn(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 6.
The segment is "白猫 黑狗 ".

関連項目

別のワイド文字列に含まれないワイド文字のみで構成される
最大の先頭セグメントの長さを返す
(function)
あるワイド文字列中のワイド文字のうち、別のワイド文字列で最初に見つかった位置を検索する
(function)