c++ stl 的string 的size() legth()区别

最近在查一个bug的时候看到这个说法,看了一下.

 

 

有几种说法

 

也有人说出一系的解释

 

VC.net   7.0中: 
size_type   length()   const 
{ //   return   length   of   sequence 
return   (_Mysize); 


size_type   size()   const 
{ //   return   length   of   sequence 
return   (_Mysize); 


GCC   3.3.3中: 
size_type 
size()   const   {   return   _M_rep()-> _M_length;   } 

size_type 
length()   const   {   return   _M_rep()-> _M_length;   } 

 

 

 

--------------------------------------------------------------------------------------------

也有另外一个说法

 

string.size()   =   string.lenth()   *   sizeof(string.item)

 

意思是说看你用什么字符...

 

 

我更赞同第二种..

可惜一直没有demo写出来分析一下

posted on 2012-08-14 16:27  Orz..  阅读(476)  评论(1编辑  收藏  举报

导航