#include <iostream>
#include <vector>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
int main()
{
vector<int> ivec;
int ival;
cout << "Enter some integers for vector(Ctrl + Z to end):" << 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;
cout << "first element from at(): " << ivec.at(0) << endl;
}
return 0;
}
對於vector第一個元素訪問的幾種方法
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.