std::wcschr(3)

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

πŸ’… std::wcschr β€” C++ Standard Library (3)

okay so bestie, welcome to std::wcschr. that's the C++ standard library's "where's that wide character at" function, and yes it's a whole mood. this page is literally all about it. πŸ¦‹


✨ NAME ✨

std::wcschr β€” finds the first occurrence of a wide character in a wide string. no cap, that's the whole gig.


πŸŽ€ Synopsis πŸŽ€

defined in header <cwchar> β€” that's your girl, go include her:

const wchar_t* wcschr( const wchar_t* str, wchar_t ch );
    wchar_t* wcschr(       wchar_t* str, wchar_t ch );

what she does: finds the first occurrence of the wide character ch in the wide string pointed to by str. that's it. that's the function. iconic behaviour honestly. ⭐


🩷 Parameters 🩷

  • str β€” pointer to the null-terminated wide string to be analyzed. yes bestie, null-terminated, she has to know where to stop reading. πŸ’€
  • ch β€” the wide character to search for. the one you're looking for. main character energy fr.

🌸 Return value 🌸

a pointer to the found character in str, OR a null pointer if no such character is found. so like… always vibe check the result before you dereference it, i'm begging you 😭


🌈 Example 🌈

// Run this code
#include <cwchar>
#include <iostream>
#include <locale>

int main()
{
    const wchar_t arr[] = L"η™½ηŒ« ι»’ηŒ« кошки";
    const wchar_t* cat = std::wcschr(arr, L'猫');
    const wchar_t* dog = std::wcschr(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";
}

and the output is giving:

The character 猫 found at position 1
The character 犬 not found

see how we're doing pointer arithmetic with cat - arr to get the position? that's the trick, bestie. iykyk 🧚


πŸ‘‘ See also πŸ‘‘

  • find β€” finds the first occurrence of the given substring (public member function of std::basic_string<CharT,Traits,Allocator>) β€” the string-class version of the vibe.
  • strchr β€” finds the first occurrence of a character (function) β€” the narrow-char edition, for when you're not doing wide stuff.
  • wcsrchr β€” finds the last occurrence of a wide character in a wide string (function) β€” same energy but from the back. different vibe entirely.
  • wcspbrk β€” finds the first location of any wide character in one wide string, in another wide string (function) β€” she's the "any of these?" girlie.
  • C documentation for wcschr β€” the OG C version, if you wanna compare notes πŸ’œ

okay that's the whole page, you ate that 🫢 this was served up fresh from http://cppreference.com, dated 2024.06.10, on the std::wcschr(3) page. go find your characters, bestie, and remember: check for that null pointer. slay πŸ’…βœ¨

πŸ“¦ where this page comes from