collate::transform

将区域设置的字符序列转换为能用于与同一区域设置类似转换的其他字符序列的字典比较的字符串。

string_type transform(
   const CharType* _First,
   const CharType* _Last
) const;

参数

  • _First
    对于第一个字符的指针将转换的序列。

  • _Last
    以上字符的指针将转换的序列。

返回值

包含转换后的字符序列的字符串。

备注

成员函数返回 do_transform(_First,_Last)。

示例

// collate_transform.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
#include <tchar.h>
using namespace std;

int main( )   
{
   locale loc ( "German_Germany" );
   _TCHAR* s1 = _T("\x00dfzz abc."); 
   // \x00df is the German sharp-s (looks like beta), 
   // it comes before z in the alphabet
   _TCHAR* s2 = _T("zzz abc."); 

   collate<_TCHAR>::string_type r1;   // OK for typedef?
   r1 = use_facet< collate<_TCHAR> > ( loc ).
      transform (s1, &s1[_tcslen( s1 )-1 ]);
   
   cout << r1 << endl;

   basic_string<_TCHAR> r2 = use_facet< collate<_TCHAR> > ( loc ).
      transform (s2, &s2[_tcslen( s2 )-1 ]);
   
   cout << r2 << endl;

   int result1 = use_facet<collate<_TCHAR> > ( loc ).compare 
      (s1, &s1[_tcslen( s1 )-1 ],  s2, &s2[_tcslen( s2 )-1 ] );

   cout << _tcscmp(r1.c_str( ),r2.c_str( )) << result1 
      << _tcscmp(s1,s2) <<endl;
}
  
  
  
  
  
  
  

要求

标头: <locale>

命名空间: std

请参见

参考

collate Class