C++之string长度
(1)使用string的成员方法length ) )取得字符串长度
)2)使用string的成员方法size ) )取得字符串长度
(3)通过strlen获取字符串长度
(4)函数实现获取字符串长度的功能
intgetstringwords (stringstrword ) intnwords ) 0; int nLen=strWord.length (; intI(0; while(Inlen )//如果是汉字,则转移到下一个if ) strword[I]0x80 ); } nWords; I; } return nWords; )总结(1)、(2)、(3)有中文的话,表示两个字;(4)不区分中英文,根据实际个数计算字符串的长度。