名稱空間
變體
操作

std::wcsrchr

來自 cppreference.com
< cpp‎ | string‎ | wide
在標頭檔案 <cwchar> 中定義
const wchar_t* wcsrchr( const wchar_t* str, wchar_t ch );
      wchar_t* wcsrchr(       wchar_t* str, wchar_t ch );

查詢寬字串 str 中寬字元 ch 的最後一次出現。

目錄

[編輯] 引數

str - 指向待分析的空終止寬字串的指標
ch - 要查詢的寬字元

[編輯] 返回值

指向 str 中找到的字元的指標,如果沒有找到該字元,則為 null 指標。

[編輯] 示例

#include <cwchar>
#include <iostream>
#include <locale>
 
int main()
{
    const wchar_t arr[] = L"白貓 黒貓 кошки";
    const wchar_t* cat = std::wcsrchr(arr, L'貓');
    const wchar_t* dog = std::wcsrchr(arr, L'犬');
 
    std::cout.imbue(std::locale("en_US.utf8"));
 
    if (cat)
        std::cout << "The character 貓 found at position " << cat - arr << '\n';
    else
        std::cout << "The character 貓 not found\n";
 
    if (dog)
        std::cout << "The character 犬 found at position " << dog - arr << '\n';
    else
        std::cout << "The character 犬 not found\n";
}

輸出

The character 貓 found at position 4
The character 犬 not found

[編輯] 參閱

在寬字串中查詢寬字元的首次出現
(函式) [編輯]
查詢字元的最後一次出現
(函式) [編輯]
查詢子串的最後一次出現
(std::basic_string<CharT,Traits,Allocator> 的 public 成員函式) [編輯]
C 文件 中的 wcsrchr