| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||
| Character classification | ||||||||||||||||||||||||||
| Character manipulation | ||||||||||||||||||||||||||
| Conversions to numeric formats | ||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||
| String manipulation | ||||||||||||||||||||||||||
| String examination | ||||||||||||||||||||||||||
| Array manipulation | ||||||||||||||||||||||||||
Defined in header <cwchar> | ||
int wmemcmp(constwchar_t* lhs,constwchar_t* rhs,std::size_t count); | ||
Compares the firstcount wide characters of the wide character arrays pointed to bylhs andrhs. 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.
Ifcount is zero, the function does nothing.
Contents |
| lhs, rhs | - | pointers to the wide character arrays to compare |
| count | - | number of wide characters to examine |
Negative value if the value of the first differing wide character inlhs is less than the value of the corresponding wide character inrhs:lhs precedesrhs in lexicographical order.
0 if allcount wide characters oflhs andrhs are equal.
Positive value if the value of the first differing wide character inlhs is greater than the value of the corresponding wide character inrhs:rhs precedeslhs in lexicographical order.
This function is not locale-sensitive and pays no attention to the values of thewchar_t objects it examines: nulls as well as invalid wide characters are compared too.
#include <clocale>#include <cwchar>#include <iostream>#include <locale>#include <string> void demo(constwchar_t* lhs,constwchar_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 ";elseif(rc<0)std::wcout<<" precedes ";elseif(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'γ'};constexprstd::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
| compares two wide strings (function)[edit] | |
| compares two buffers (function)[edit] | |
| compares a certain amount of characters from two wide strings (function)[edit] | |
C documentation forwmemcmp | |