locale::operator()

比较两个 basic_string 对象。

template<Class CharType, class Traits, class Allocator>
    bool operator()(
        const basic_string<CharType, Traits, Allocator >& _Left,
        const basic_string<CharType, Traits, Allocator >& _Right
    ) const;

参数

  • _Left
    左侧字符串。

  • _Right
    右侧字符串。

返回值

成员函数返回:

  • (1,如果第一个序列比第二个序列较低比较。

  • +1,如果第二个序列比第一个序列较低比较。

  • 0,如果序列为等效的。

备注

成员函数无效:

const collate<CharType>& fac = use_fac<collate<CharType> >(*this);
return (fac.compare(_Left.begin( ),_Left.end( ),_Right.begin( ),_Right.end( )) < 0);

因此,您可以使用区域设置对象,函数对象。

示例

// locale_op_compare.cpp
// compile with: /EHsc
#include <iostream>
#include <string>
#include <locale>

int main( ) 
{
   using namespace std;
   wchar_t *sa = L"ztesting";
   wchar_t *sb = L"\0x00DFtesting";
   basic_string<wchar_t> a( sa );
   basic_string<wchar_t> b( sb );

   locale loc( "German_Germany" );
   cout << loc( a,b ) << endl;

   const collate<wchar_t>& fac = use_facet<collate<wchar_t> >( loc );
   cout << ( fac.compare( sa, sa + a.length( ),
       sb, sb + b.length( ) ) < 0) << endl;
}
  

要求

页眉: <区域设置>

命名空间: std

请参见

参考

locale 类