现在的位置: 首页 > 综合 > 正文

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

2013年05月08日 ⁄ 综合 ⁄ 共 527字 ⁄ 字号 评论关闭

最近在查一个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写出来分析一下

抱歉!评论已关闭.