c++ primer习题9.24

来源:互联网 发布:背包推荐 知乎 编辑:程序博客网 时间:2024/06/05 20:12
/**分别使用下标操作符、front函数以及begin函数*获取vector容器的第一个元素*/#include <iostream>#include <vector>using namespace std;int main(){    vector<int> ivec;    int ival;    cout<<"Enter some integers for vector:"<<endl;    while(cin>>ival)        ivec.push_back(ival);    if(ivec.empty())        cout<<"No element!"<<endl;    else    {        cout<<"first element from subscript: "<<ivec[0]<<endl;        cout<<"first element from front(): "<<ivec.front()<<endl;        cout<<"first element from begin(): "<<*ivec.begin()<<endl;    }    return 0;}

原创粉丝点击