std::wcsrchr(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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 of std::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