名稱空間
變體
操作

std::wmemchr

來自 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 - 指向要檢查的寬字元陣列的指標
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

[編輯] 另請參閱

在陣列中搜索字元的第一次出現
(函式) [編輯]
查詢字元的第一次出現
(函式) [編輯]
在寬字串中查詢寬字元的首次出現
(函式) [編輯]
尋找第一個滿足特定條件的元素
(函式模板) [編輯]
C 文件 用於 wmemchr