std::wmemchr(3)
๐ฆ std::wmemchr(3) ๐ฆ
okay so bestie, welcome to the C++ Standard Libary manual page for std::wmemchr โ yes, the manual name is literally โC++ Standard Libaryโ and we are not fixing it, we respect the typo ๐
. This one is a wide-character search function, and it's lowkey iconic.
โจ NAME โจ
std::wmemchr - std::wmemchr
it's giving self-titled debut album โ the NAME field is just the function name twice, and honestly? slay.
๐ Synopsis ๐
Defined in header <cwchar> ๐
const wchar_t* wmemchr( const wchar_t* ptr, wchar_t ch, std::size_t count ); (1)
wchar_t* wmemchr( wchar_t* ptr, wchar_t ch, std::size_t count ); (2)
okay so what does it do? It locates the first occurrence of wide character ch in the initial count wide characters of the wide character array pointed to by ptr. fr fr, it's snooping through the first count wide chars and looking for your fave.
๐จ caveat bestie: ifcountis zero, the function returns a null pointer. no searching, no vibes, justnullptr. periodt.
๐ Parameters ๐
ptrโ pointer to the wide character array to be examined. the alley we're snooping through ๐chโ wide character to search for. the one we want ๐countโ number of wide characters to examine. how many slots we're checking, no more no less โจ
๐ซถ Return value ๐ซถ
Pointer to the location of the wide character, or a null pointer if no such character is found. so if it finds ch, you get the address; if not, you get nullptr and a little moment of silence ๐ญ
๐ Example ๐
// Run this code
#include <clocale>
#include <cwchar>
#include <iostream>
#include <locale>
int main()
{
const wchar_t str[] =
L"่ฏบไธ่ฝปไฟก๏ผๆ
ไบบไธ่ดๆ\0่ฏบไธ่ฝป่ฎธ๏ผๆ
ๆไธ่ดไบบใ";
wchar_t target = L'่ฎธ';
const std::size_t sz = sizeof str / sizeof *str;
if (const wchar_t* result = std::wmemchr(str, target, sz))
{
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout.imbue(std::locale("en_US.utf8"));
std::wcout << "Found '" << target << "' at position " << result
- str << '\n';
}
}
literally the code is doing the whole detective arc: it searches the wide string for L'่ฎธ', and if it finds it, it sets the locale and prints the position. ate and left no crumbs ๐
โญ Possible output โญ
Found '่ฎธ' at position 14
๐ See also ๐
memchrโ searches an array for the first occurrence of a character (function)strchrโ finds the first occurrence of a character (function)wcschrโ finds the first occurrence of a wide character in a wide string (function)findfind_ifโ finds the first element satisfying specific criteriafind_if_notโ (function template) โ (C++11)- C documentation for
wmemchr
and that's the page, bestie ๐ซถ sourced from the page URL http://cppreference.com, dated 2024.06.10, and filed under the std::wmemchr(3) page. go forth and search your wide chars with main character energy ๐โจ
๐ฆ 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