std::wmemcmp(3)
π std::wmemcmp(3) β C++ Standard Libary edition π
Okay bestie, welcome to the std::wmemcmp page β yes, the manual name is literally C++ Standard Libary up top, spelling and all ππ
. This is the wide-character comparison function you need to know.
πΈ NAME πΈ
std::wmemcmp β std::wmemcmp (iconic, no notes, periodt π
β¨)
π§ Synopsis π§
Defined in header <cwchar>
int wmemcmp( const wchar_t* lhs, const wchar_t* rhs, std::size_t count );
It compares the first count wide characters of the wide character arrays pointed to by lhs and rhs. The comparison is done lexicographically.
The sign of the result is the sign of the difference between the values of the first pair of wide characters that differ in the arrays being compared.
If count is zero, the function does nothing. Literally nothing, bestie. π«Ά
π¦ Parameters π¦
lhs,rhsβ pointers to the wide character arrays to compare.countβ number of wide characters to examine.
π Return value π
- Negative value if the value of the first differing wide character in
lhsis less than the value of the corresponding wide character inrhs:lhsprecedesrhsin lexicographical order. 0if allcountwide characters oflhsandrhsare equal.- Positive value if the value of the first differing wide character in
lhsis greater than the value of the corresponding wide character inrhs:rhsprecedeslhsin lexicographical order.
π Notes π
This function is not locale-sensitive and pays no attention to the values of the wchar_t objects it examines: nulls as well as invalid wide characters are compared too. It's giving equal-opportunity wide-character comparison, no cap. β¨
π₯ Example π₯
// Run this code
#include <clocale>
#include <cwchar>
#include <iostream>
#include <locale>
#include <string>
void demo(const wchar_t* lhs, const wchar_t* rhs, std::size_t sz)
{
std::wcout << std::wstring(lhs, sz);
int rc = std::wmemcmp(lhs, rhs, sz);
if (rc == 0)
std::wcout << " compares equal to ";
else if (rc < 0)
std::wcout << " precedes ";
else if (rc > 0)
std::wcout << " follows ";
std::wcout << std::wstring(rhs, sz) << " in lexicographical order\n";
}
int main()
{
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout.imbue(std::locale("en_US.utf8"));
wchar_t a1[] = {L'Ξ±',L'Ξ²',L'Ξ³'};
constexpr std::size_t sz = sizeof a1 / sizeof *a1;
wchar_t a2[sz] = {L'Ξ±',L'Ξ²',L'Ξ΄'};
demo(a1, a2, sz);
demo(a2, a1, sz);
demo(a1, a1, sz);
}
π Possible output π
Ξ±Ξ²Ξ³ precedes Ξ±Ξ²Ξ΄ in lexicographical order
Ξ±Ξ²Ξ΄ follows Ξ±Ξ²Ξ³ in lexicographical order
Ξ±Ξ²Ξ³ compares equal to Ξ±Ξ²Ξ³ in lexicographical order
π See also π
wcscmpβ compares two wide strings (function).memcmpβ compares two buffers (function).wcsncmpβ compares a certain amount of characters from two wide strings (function).- C documentation for
wmemcmp.
source/version/date tea β: this little page comes from http://cppreference.com, dated 2024.06.10, and it's serving std::wmemcmp(3) realness. mwah ππ
π¦ 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