名前空間
変種
操作

std::wmemchr

提供: cppreference.com
< cpp‎ | string‎ | wide
ヘッダ <cwchar> で定義
const wchar_t* wmemchr( const wchar_t* ptr, wchar_t ch, std::size_t count );
      wchar_t* wmemchr(       wchar_t* ptr, wchar_t ch, std::size_t count );

ptr の指すワイド文字配列の先頭 count 個のワイド文字からワイド文字 ch が最初に現れる位置を探します。

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

目次

[編集] 引数

ptr - 調べるワイド文字配列を指すポインタ
ch - 検索するワイド文字
count - 調べるワイド文字数

[編集] 戻り値

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

[編集]

#include <iostream>
#include <cwchar>
#include <clocale>
#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

[編集] 関連項目

文字が現れる最初の位置を配列から探します
(関数) [edit]
文字が現れる最初の位置を探します
(関数) [edit]
ワイド文字列中のワイド文字が現れる最後の位置を探します
(関数) [edit]
一定の基準を満たす最初の要素を探します
(関数テンプレート) [edit]