std::wcsrchr(3)
π NAME π
Okay so bestie, welcome to the page for std::wcsrchr β and yes, the name is literally std::wcsrchr too π
. This is from the C++ Standard Libary manual, and it's giving βfind the last wide-character matchβ main character energy. π¦
β¨ Synopsis β¨
Defined in header <cwchar> π
const wchar_t* wcsrchr( const wchar_t* str, wchar_t ch );
wchar_t* wcsrchr( wchar_t* str, wchar_t ch );
So what does it do? Its whole job is to find the last occurrence of the wide character ch in the wide string pointed to by str. Like, it goes looking for the final match, not the first one β periodt. π₯
π Parameters π
strβ pointer to the null-terminated wide string to be analyzed. That's your string bestie, null-terminated and ready for analysis π.chβ the wide character to search for. This is the one you're hunting for. π
πΈ Return value πΈ
A pointer to the found character in str π
, or a null pointer if no such character is found π. Match found = pointer, no match = null pointer. That's the vibe.
π± Example π±
Here's the code, complete with multilingual cat energy πΎβ¨:
// Run this code
#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";
}
β Output β
And the output is exactly this, no cap:
The character η« found at position 4
The character η¬ not found
π See also π
wcschrβ finds the first occurrence of a wide character in a wide string (function) πstrrchrβ finds the last occurrence of a character (function) π₯rfindβ find the last occurrence of a substring (public member function ofstd::basic_string<CharT,Traits,Allocator>) π- C documentation for
wcsrchrπ¦
That's the whole page, bestie! π Source: http://cppreference.com β¨ Version/date: 2024.06.10 π Page: std::wcsrchr(3) π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms