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 wcscoll(constwchar_t* lhs,constwchar_t* rhs); | ||
Compares two null-terminated wide strings according to the locale most recently installed bystd::setlocale, as defined by theLC_COLLATE category.
Contents |
lhs, rhs | - | pointers to the null-terminated wide strings to compare |
Negative value iflhs isless than (precedes)rhs.
0 iflhs isequal torhs.
Positive value iflhs isgreater than (follows)rhs.
Collation order is the dictionary order: the position of the letter in the national alphabet (itsequivalence class) has higher priority than its case or variant. Within an equivalence class, lowercase characters collate before their uppercase equivalents and locale-specific order may apply to the characters with diacritics. In some locales, groups of characters compare as singlecollation units. For example,"ch" in Czech follows"h" and precedes"i", and"dzs" in Hungarian follows"dz" and precedes"g".
#include <clocale>#include <iostream> void try_compare(constwchar_t* p1,constwchar_t* p2){if(std::wcscoll(p1, p2)<0)std::wcout<< p1<<" before "<< p2<<'\n';elsestd::wcout<< p2<<" before "<< p1<<'\n';} int main(){std::setlocale(LC_ALL,"en_US.utf8");std::wcout<<"In the American locale: "; try_compare(L"hrnec", L"chrt"); std::setlocale(LC_COLLATE,"cs_CZ.utf8");std::wcout<<"In the Czech locale: "; try_compare(L"hrnec", L"chrt"); std::setlocale(LC_COLLATE,"en_US.utf8");std::wcout<<"In the American locale: "; try_compare(L"år", L"ängel"); std::setlocale(LC_COLLATE,"sv_SE.utf8");std::wcout<<"In the Swedish locale: "; try_compare(L"år", L"ängel");}
Output:
In the American locale: chrt before hrnecIn the Czech locale: hrnec before chrtIn the American locale: ängel before årIn the Swedish locale: år before ängel
compares two strings in accordance to the current locale (function)[edit] | |
[virtual] | compares two strings using this facet's collation rules (virtual protected member function of std::collate<CharT> )[edit] |
transform a wide string so thatwcscmp would produce the same result aswcscoll (function)[edit] | |
C documentation forwcscoll |