C++ 中的wcsrchr() 函數搜索寬字符串中最後一次出現的寬字符。
wcsrchr() 函數在<cwchar> 頭文件中定義。
wcsrchr()原型
const wchar_t* wcsrchr( const wchar_t* str, wchar_t ch ); wchar_t* wcsrchr( wchar_t* str, wchar_t ch );
wcsrchr() 函數有兩個參數:str
和 ch
。它在 str
指向的寬字符串中搜索最後一次出現的寬字符 ch
。
參數:
ptr
:指向要搜索的空終止寬字符串的指針。ch
:要搜索的寬字符。
返回:
如果找到 ch
,則 wcsrchr() 函數返回指向 str
中 ch
的最後一個位置的指針,否則返回空指針。
示例:wcsrchr() 函數如何工作?
#include <cwchar>
#include <clocale>
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.utf8");
wchar_t str[] = L"\u222b\u222e\u2231\u2211\u220f\u222b";
wchar_t ch = L'∫';// Integral sign
wchar_t* p = wcsrchr(str, ch);
if (p)
wcout << L"Last position of " << ch << L" in \"" << str << "\" is " << (p-str);
else
wcout << ch << L" is not present \"" << str << L"\"";
return 0;
}
運行程序時,輸出將是:
Last position of ∫ in "∫∮∱∑∏∫" is 5
相關用法
- C++ wcsrchr()用法及代碼示例
- C++ wcsrtombs()用法及代碼示例
- C++ wcstold()用法及代碼示例
- C++ wcsftime()用法及代碼示例
- C++ wcstod()用法及代碼示例
- C++ wcscspn()用法及代碼示例
- C++ wcsncmp()用法及代碼示例
- C++ wcstok()用法及代碼示例
- C++ wcsstr()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ wcslen()用法及代碼示例
- C++ wcsspn()用法及代碼示例
- C++ wcschr()用法及代碼示例
- C++ wcstof()用法及代碼示例
- C++ wcstol()用法及代碼示例
- C++ wcspbrk()用法及代碼示例
- C++ wcscat()用法及代碼示例
- C++ wcscoll()用法及代碼示例
- C++ wcsncat()用法及代碼示例
- C++ wcscpy()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ wcsrchr()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。