设为首页 加入收藏

TOP

4.2.10 使用empty()成员函数
2013-10-07 14:44:48 来源: 作者: 【 】 浏览:55
Tags:4.2.10 使用 empty 成员 函数

4.2.10  使用empty()成员函数

最后,程序检查主人公物品栏中是否还有任何物品。

  1. if (inventory.empty())  
  2. {  
  3. cout << "\nYou have nothing.\n";  
  4. }  
  5. else  
  6. {  
  7. cout << "\nYou have at least one item.\n";  
  8. }  

vector的成员函数empty()的作用和string的成员函数empty()一样。如果vector对象为空,则返回true;否则返回false。因为inventory在此处为空,所以程序显示消息"You have nothing."。
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇4.3.2 迭代器的声明 下一篇4.2.9 使用clear()成员函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: