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 | ||||||||||||||||||||||||||||||||||||
Character array functions | ||||||||||||||||||||||||||||||||||||
Miscellaneous | ||||||||||||||||||||||||||||||||||||
Defined in header <cstring> | ||
int strcoll(constchar* lhs,constchar* rhs); | ||
Compares two null-terminated byte strings according to the current locale as defined by theLC_COLLATE category.
Contents |
lhs, rhs | - | pointers to the null-terminated byte strings to compare |
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 <cstring>#include <iostream> int main(){std::setlocale(LC_COLLATE,"cs_CZ.utf8");// Alternatively, ISO-8859-2 (a.k.a. Latin-2)// may also work on some OS:// std::setlocale(LC_COLLATE, "cs_CZ.iso88592"); constchar* s1="hrnec";constchar* s2="chrt"; std::cout<<"In the Czech locale: ";if(std::strcoll(s1, s2)<0)std::cout<< s1<<" before "<< s2<<'\n';elsestd::cout<< s2<<" before "<< s1<<'\n'; std::cout<<"In lexicographical comparison: ";if(std::strcmp(s1, s2)<0)std::cout<< s1<<" before "<< s2<<'\n';elsestd::cout<< s2<<" before "<< s1<<'\n';}
Output:
In the Czech locale: hrnec before chrtIn lexicographical comparison: chrt before hrnec
compares two wide 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 string so thatstrcmp would produce the same result asstrcoll (function)[edit] | |
C documentation forstrcoll |