C++11 for的新版本

使用新版本的C++关键字for的新语法。

同时也有新版本的C++关键字auto,自动类型推断,可以推断返回类型,用于声明新的变量。 

#include <iostream>
#include <vector>
#include <string>
using std::string;

using std::cout;
using std::endl;
using std::vector;

int main()
{

    vector <string> coll;
    coll.push_back("fsd");
    coll.push_back("fsd");
    coll.push_back("fsd");
    coll.push_back("fsd");
    coll.push_back("fsd");
    /*新建里一个容器的元素类型一样的参数 ptr 
      如果不清楚是什么类型
      可以使用auto,使用类型推断来建立ptr的类型*/
    for(string ptr : coll)//使用C++11 新增加的关键字for的新版本
    {
        cout<<ptr<<endl;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值