Namespaces
Variants

std:: wcscoll

From cppreference.net
헤더 파일에 정의됨 <cwchar>
int wcscoll ( const wchar_t * lhs, const wchar_t * rhs ) ;

널 종료 와이드 문자열 두 개를 가장 최근에 std::setlocale 으로 설치된 로케일에 따라, LC_COLLATE 카테고리에서 정의된 방식으로 비교합니다.

목차

매개변수

lhs, rhs - 비교할 null로 종료되는 와이드 문자열에 대한 포인터

반환값

lhs rhs 보다 작은 경우 (선행하는 경우) 음수 값.

0 만약 lhs 같으면 rhs .

lhs rhs 보다 큰 경우 (뒤따르는 경우) 양의 값.

참고 사항

정렬 순서는 사전 순서입니다: 문자가 국가별 알파벳에서 차지하는 위치(그것의 동등 클래스 )는 대소문자나 변형보다 우선순위가 높습니다. 동등 클래스 내에서는 소문자가 해당 대문자보다 먼저 정렬되며, 발음 구별 기호가 있는 문자에는 로캘별 순서가 적용될 수 있습니다. 일부 로캘에서는 문자 그룹이 단일 정렬 단위 로 비교됩니다. 예를 들어, "ch" 는 체코어에서 "h" 다음에 오고 "i" 앞에 옵니다. 또한 "dzs" 는 헝가리어에서 "dz" 다음에 오고 "g" 앞에 옵니다.

예제

#include <clocale>
#include <iostream>
void try_compare(const wchar_t* p1, const wchar_t* p2)
{
    if (std::wcscoll(p1, p2) < 0)
        std::wcout << p1 << " before " << p2 << '\n';
    else
        std::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");
}

출력:

In the American locale: chrt before hrnec
In the Czech locale: hrnec before chrt
In the American locale: ängel before år
In the Swedish locale: år before ängel

참고 항목

현재 로캘에 따라 두 문자열을 비교합니다
(함수)
[virtual]
이 패싯의 문자열 정렬 규칙을 사용하여 두 문자열을 비교합니다
( std::collate<CharT> 의 가상 protected 멤버 함수)
wcscmp wcscoll 과 동일한 결과를 생성하도록 와이드 문자열을 변환합니다
(함수)
C documentation for wcscoll