Namespaces
Variants

std:: wmemchr

From cppreference.net
定義先ヘッダ <cwchar>
const wchar_t * wmemchr ( const wchar_t * ptr, wchar_t ch, std:: size_t count ) ;
(1)
wchar_t * wmemchr ( wchar_t * ptr, wchar_t ch, std:: size_t count ) ;
(2)

ワイド文字配列 ptr が指す先頭 count ワイド文字内で、ワイド文字 ch が最初に出現する位置を検索します。

count がゼロの場合、この関数はヌルポインタを返します。

目次

パラメータ

ptr - 検査対象のワイド文字配列へのポインタ
ch - 検索対象のワイド文字
count - 検査するワイド文字の数

戻り値

ワイド文字の位置へのポインタ、またはそのような文字が見つからない場合はヌルポインタ。

#include <clocale>
#include <cwchar>
#include <iostream>
#include <locale>
int main()
{
    const wchar_t str[] = L"诺不轻信,故人不负我\0诺不轻许,故我不负人。";
    wchar_t target = L'许';
    const std::size_t sz = sizeof str / sizeof *str;
    if (const wchar_t* result = std::wmemchr(str, target, sz))
    {
        std::setlocale(LC_ALL, "en_US.utf8");
        std::wcout.imbue(std::locale("en_US.utf8"));
        std::wcout << "Found '" << target << "' at position " << result - str << '\n';
    }
}

出力例:

Found '许' at position 14

関連項目

配列内で最初に現れる文字を検索する
(function)
文字の最初の出現位置を検索する
(function)
ワイド文字列内でワイド文字の最初の出現位置を検索する
(function)
特定の条件を満たす最初の要素を検索する
(function template)
C documentation for wmemchr