collate::compare
根據其 Facet 特定規則的比較兩個字元的序列或相等比較。
int compare(
const CharType* _First1,
const CharType* _Last1,
const CharType* _First2,
const CharType* _Last2
) const;
參數
_First1
對第一個元素的指標在要比較的第一個序列。_Last1
到最後一個元素的指標在要比較的第一個序列。_First2
對第一個元素的指標在要比較的第二個序列。_Last2
到最後一個元素的指標在要比較的第二個序列。
傳回值
成員函式傳回:
– 1,如果第一個序列比較小於第二個序列。
+1,如果第二個序列比較小於第一個序列。
0 個項目,如果序列是相等的。
備註
第一個序列比較較少,則有更小位於序列的最早的不等於,或,則為,如果不等於不存在,不過,第一個序列較短。
成員函式會傳回 do_compare(_First1、 _Last1、 _First2, _Last2)。
範例
// collate_compare.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <tchar.h>
using namespace std;
int main() {
locale loc ( "German_germany" );
_TCHAR * s1 = _T("Das ist wei\x00dfzz."); // \x00df is the German sharp-s, it comes before z in the German alphabet
_TCHAR * s2 = _T("Das ist weizzz.");
int result1 = use_facet<collate<_TCHAR> > ( loc ).
compare ( s1, &s1[_tcslen( s1 )-1 ], s2, &s2[_tcslen( s2 )-1 ] );
cout << result1 << endl;
locale loc2 ( "C" );
int result2 = use_facet<collate<_TCHAR> > ( loc2 ).
compare (s1, &s1[_tcslen( s1 )-1 ], s2, &s2[_tcslen( s2 )-1 ] );
cout << result2 << endl;
}
範例輸出
-1
1
需求
標題: <地區設定>
命名空間: std