加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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

(2011-01-14 10:36:06)
标签:

游戏

分类: C程序例子
#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;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有