您的位置:首页 > 其它

对于vector第一个元素访问的几种方法

2012-09-05 11:46 465 查看
#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;
}


转载来自:http://blog.sina.com.cn/s/blog_6aaa7e840100oe78.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: