Namespaces
Variants

std:: wcspbrk

From cppreference.net
定義済みヘッダー <cwchar>
const wchar_t * wcspbrk ( const wchar_t * dest, const wchar_t * src ) ;
wchar_t * wcspbrk ( wchar_t * dest, const wchar_t * src ) ;

dest が指すワイド文字列の中で、 src が指すワイド文字列にも含まれる最初の文字を検索します。

目次

パラメータ

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

戻り値

dest 内の最初の文字へのポインタで、 src 内にも存在するもの。そのような文字が存在しない場合はヌルポインタ。

注記

この名前は「ワイド文字列ポインタブレーク」を意味します。これは、セパレータ(「ブレーク」)文字の最初の文字へのポインタを返すためです。

#include <cwchar>
#include <iomanip>
#include <iostream>
int main()
{
    const wchar_t* str = L"Hello world, friend of mine!";
    const wchar_t* sep = L" ,!";
    unsigned int cnt = 0;
    do
    {
        str = std::wcspbrk(str, sep); // セパレータを検索
        std::wcout << std::quoted(str) << L'\n';
        if (str)
            str += std::wcsspn(str, sep); // セパレータをスキップ
        ++cnt; // 単語カウントをインクリメント
    } while (str && *str);
    std::wcout << L"There are " << cnt << L" words\n";
}

出力:

" world, friend of mine!"
", friend of mine!"
" of mine!"
" mine!"
"!"
There are 5 words

関連項目

他のワイド文字列に含まれないワイド文字のみで構成される
最大の先頭セグメントの長さを返す
(function)
ワイド文字列内でワイド文字が最初に現れる位置を検索する
(function)
区切り文字セット内の任意の文字が最初に現れる位置を検索する
(function)
C documentation for wcspbrk