#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<int> ints {, , };
vector<string> fruits {"orange", "apple", "raspberry"};
vector<char> empty; // Sums all integers in the vector ints (if any), printing only the result.
int sum = ;
for (auto it = ints.cbegin(); it != ints.cend(); it++)
sum += *it;
cout << "Sum of ints: " << sum << "\n"; // 输出容器的第一个元素
cout << "First fruit: " << *fruits.begin() << "\n"; if (empty.begin() == empty.end())
cout << "vector 'empty' is indeed empty.\n";
}

c++ 判断容器是否为空的更多相关文章

  1. [Python]判断序列是否为空的正确姿势

    本篇文章起源于StackOverflow上一个热度非常高的问题: 我该如何判断一个Python列表是否为空? @Ray Vega (提问者) 举例说明,现在我得到了如下代码: a = [] 我如何该检 ...

  2. java中判断list是否为空的用法

    1.如果想判断list是否为空,可以这么判断: if(null == list || list.size() ==0 ){ //为空的情况 }else{ //不为空的情况 } 2.list.isEmp ...

  3. JS心得——判断一个对象是否为空

    判断一个对象是否为空对象,本文给出三种判断方法: 最常见的思路,for...in...遍历属性,为真则为"非空数组":否则为"空数组" 2.通过JSON自带的. ...

  4. iOS 判断字符串是否为空

    写一个字符串的扩展,实现判断字符串是否为空- (BOOL) isBlankString { if ([self isEqualToString:@"(null)"]) { retu ...

  5. iOS判断数组不为空

    用([array count]==0 )来判断是否为空,都是坑,如果array为空的话,执行count就会直接报错,程序崩溃退出. 正确判断NSArray是否为空的方法: if(array != ni ...

  6. iOS 判断数组是否为空

    有人说可以用([array count]==0 )来判断是否为空,都是坑,如果array为空的话,执行count就会直接报错,程序崩溃退出. 正确判断NSArray是否为空的方法:用 (!array) ...

  7. freemarker判断对象是否为空

    freemarker中显示某对象使用 ${name}.   但如果name为null,freemarker就会报错.如果需要判断对象是否为空: <#if name??> …… </# ...

  8. PHP 判断数组是否为空的5大方法

    1. isset功能:判断变量是否被初始化 说明:它并不会判断变量是否为空,并且可以用来判断数组中元素是否被定义过 注意:当使用isset来判断数组元素是否被初始化过时,它的效率比array_key_ ...

  9. 转:判断DATASET是否为空

    http://blog.sina.com.cn/jiangshuqin2010 1,if(ds == null) 这是判断内存中的数据集是否为空,说明DATASET为空,行和列都不存在!! 2,if( ...

随机推荐

  1. 【BZOJ1001】[BeiJing2006]狼抓兔子 对偶图最短路

    [BZOJ1001][BeiJing2006]狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子 ...

  2. javascript飞机大战-----0010完整版代码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 【转载】网络安全---Strurts2漏洞介绍

    Apache Struts2 作为世界上最流行的 Java Web 服务器框架之一,3 月 7 日带来了本年度第一个高危漏洞——CVE编号 CVE-2017-5638 .其原因是由于 Apache S ...

  4. HDU_3193_Find the hotel

    Find the hotel Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. RSA library

  6. linux: convmv =-======pkgs.org

    convmv 不同系统文件名转化 windows: gbk linux: utf8 wget--url coding. vim ---encoding,termcode, fileencoding, ...

  7. 关于Python装饰器内层函数为什么要return目标函数的一些个人见解

    https://blog.csdn.net/try_test_python/article/details/80802199 前几天在学装饰器的时候,关于装饰器内层函数调用目标函数时是否return目 ...

  8. Scala面向对象和模式匹配

    我们要封装数据,定义模板等操作,所以我们需要面向对象. 一.scala中的单例对象 在scala当中,是没有static的,scala给我们提供了单例模式的实现方法.就是使用关键字object. st ...

  9. Day01 html详解

      day01 html详解   1.html的简介     1.1 什么是html?         - HyperText Markup Language:超文本标记语言,网页语言         ...

  10. centos samba/squid 配置 samba配置 smbclient mount fstab自动挂载samba curl -xlocalhost:3128 www.qq.com squid配置 3128 DNSPOD 第二十七节课

    centos  samba/squid 配置  samba配置 smbclient  mount fstab自动挂载samba curl -xlocalhost:3128 www.qq.com squ ...