#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. iOS面试3

    转:http://studentdeng.github.io/blog/2014/02/11/baidu-interview/ 百度面试 FEB 11TH, 2014 | COMMENTS 百度移动云 ...

  2. centos6.5安装sendmail

    1.下载安装sendEmail(下载绿色版,解压可直接使用) wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1. ...

  3. linux设置安全连接设置(私钥)

    1.私钥制作工具:puttygen 连接工具:xshell和putty. 2.制作私钥和公钥 a.打开puttygen点击Generate生产公钥和私钥(鼠标需要晃动,进度条才会前进) b. 设置标签 ...

  4. angular-translate国际化

    1.<h1>{{"hello" | translate}}</h1>2.<h1 ng-bind-html="'hello' | transl ...

  5. POI3的资料整理

    转自http://aman.cao.blog.163.com/blog/static/32951336201010823557408/ POI3的资料整理一.POI简介 Jakarta POI 是ap ...

  6. Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure stylesheet 非全站https

    Mixed Content: The page at 'https://a.t.com/login' was loaded over HTTPS, but requested an insecure ...

  7. Modulo operation

    Modulo operation - Wikipedia https://en.wikipedia.org/wiki/Modulo_operation https://baike.baidu.com/ ...

  8. 以jar包的形式来使用前端的各种框架、组件。

    springboot(二):web综合开发 - 纯洁的微笑博客 http://www.ityouknow.com/springboot/2016/02/03/spring-boot-web.html ...

  9. 锁、volatile、CAS 比较

    一.锁的劣势 (1) 在JDK1.5之前都是使用synchronized关键字保证同步的,这种通过使用一致的锁定协议来协调对共享状态的访问,可以确保无论哪个线程持有守 护变量的锁,都采用独占的方式来访 ...

  10. Android(十六 ) android 与蓝牙串口通讯

    1.得到蓝牙适配器 BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 2.打开蓝牙 if (!mBl ...