/*
*分别使用下标操作符、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;
}
c++ primer习题9.24
最新推荐文章于 2024-06-04 00:29:08 发布