名前空間
変種
操作

std::wmemchr

From cppreference.com
< cpp‎ | string‎ | wide
 
 
 
 
ヘッダ <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 - 検索対象のワイド文字列へのポインタ
文字 - 検索するワイド文字
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

[編集] 関連項目

配列から文字が最初に出現する箇所を検索する
(関数) [編集]
最初に出現する文字を見つける
(関数) [編集]
ワイド文字列内でワイド文字が最初に現れる場所を見つける
(関数) [編集]
特定の基準を満たす最初の要素を見つける
(関数テンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)