3.3.9 使用empty()成员函数

2013-10-07 14:42:50 · 作者: · 浏览: 63

3.3.9  使用empty()成员函数

empty()成员函数返回bool型值,如果string对象为空,则返回true,否则返回false。下面的代码使用了empty():

  1. if (phrase.empty())  
  2. {  
  3. cout << "\nThe phrase is no more.\n";  
  4. }  

因为phrase等于空字符串,所以phrase.empty()返回true,且屏幕显示消息"The phrase is no more."