std::wcschr(3)
π 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 ofstd::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
- 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