VC++ C++ C# Algorithm

C++博客 首页 新随笔 联系 聚合 管理
  21 Posts :: 3 Stories :: 31 Comments :: 0 Trackbacks
#include  < cassert >
#include 
< cctype >
#include 
< cmath >
#include 
< cstddef >
#include 
< ostream >
#include 
< string >
using  std::allocator;
using
 std::basic_string;
using  std:: string
;
using
 std::char_traits;
using
 std::ostream;
using
 std::tolower;
using
 std::tolower;
class  ichar_traints: public  char_traits < char >

{
public
:
   
static   int  compare( const   char   * str1, const   char   *
str2,size_t n)
   
{
       
for (size_t i = 0 ; i < n; i ++
)
       
{
           
if (str1 == 0
)
               
return   - 1
;
           
else   if (str2 == 0
)
               
return   1
;
           
else   if (toupper( * str1) < toupper( *
str2))
               
return   - 1
;
           
else   if (toupper( * str1) > toupper( *
str2))
               
return   1
;
           assert(tolower(
* str1) == tolower( *
str2));
           str1
++
;
           str2
++
;

       }

       
return   0 ;
   }

}
;
typedef basic_string
< char ,ichar_traints >
 istring;
inline ostream
&   operator << (ostream  & os,istring &
 str)
{
    os
<< string
(str.c_str());
}

int  _tmain( int  argc, _TCHAR *  argv[])
{
      //建立二个字符大小写不同的串
    istring s1
= " qianweifeng "
;
    istring s2
= " QianweiFeng "
;
    std::cout
<<
s1.compare(s2);
    
int
 pause;
    std::cin
>>
pause;
    
return   0
;
}
摘自Thinking in C++
posted on 2006-12-26 15:20 大熊猫 阅读(591) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理