STL front() ,back()和begin(),end()区别
首先看看vector里面的:
reference front();
const_reference front() const; queue里面的;
value_type& front();
const value_type& front() const; 一般,reference定义为value_type& ,const_reference定义为const value_type&,所以上面2者是等同的。 也就是front()返回第一个元素的引用,back()返回最后一个元素的引用。 而begin()和end()返回的是迭代器:
iterator begin();
const_iterator begin() const; iterator一般等同于value_type *. 更重要的是,end()返回最后一个元素的下一个位置,而back()是返回最后一个元素。
back()
Returns a reference to the last element in the vector. Unlike member vector::end, which returns an iterator just past this element, this function returns a direct reference. Calling this function on an empty container causes undefined behavior.
STL front() ,back()和begin(),end()区别的更多相关文章
- STL,ATL,WTL的联系与区别
STL 即 Standard Template Library STL(标准模板库)是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov. ...
- STL中mem_fun与mem_fun_ref的区别[转]
http://www.cnblogs.com/Purple_Xiapei/archive/2012/05/27/2520483.html STL中mem_fun和mem_fun_ref的用法 分类: ...
- STL 1–迭代器std::begin()和std::end()使用
迭代器是一个行为类似于指针的模板类对象.只需要迭代器iter指向一个有效对象,就可以通过使用*iter解引用的方式来获取一个对象的引用.通常会使用一对迭代器来定义一段元素,可以是任意支持迭代器对象的元 ...
- suseoj 1208: 排列问题 (STL, next_permutation(A.begin(), A.end()))
1208: 排列问题 时间限制: 1 Sec 内存限制: 128 MB提交: 2 解决: 2[提交][状态][讨论版][命题人:liyuansong] 题目描述 全排列的生成就是对于给定的字符集或 ...
- STL库学习笔记(待补充QAQ
几百年前就说要学STL了然后现在还没动呢QAQ总算还是克服了懒癌决定学下QAQ 首先港下有哪几个vector listset map stack queue,大概就这些? 然后因为有几个基本操作每个都 ...
- STL源码剖析——序列式容器#1 Vector
在学完了Allocator.Iterator和Traits编程之后,我们终于可以进入STL的容器内部一探究竟了.STL的容器分为序列式容器和关联式容器,何为序列式容器呢?就是容器内的元素是可序的,但未 ...
- 《STL源代码分析》---stl_list.h读书笔记
STL在列表list它是一种经常使用的容器.list不连续双向链表在内存,而且是环形. 理解列表如何操作的详细信息,然后.阅读STL名单上的代码是最好的方法. G++ 2.91.57.cygnus\c ...
- C++ STL源代码学习(list篇)
///STL list为双向循环链表 struct _List_node_base { _List_node_base* _M_next; _List_node_base* _M_prev; }; t ...
- STL源代码剖析 容器 stl_list.h
本文为senlie原创.转载请保留此地址:http://blog.csdn.net/zhengsenlie list ----------------------------------------- ...
随机推荐
- android解决内存溢出的问题(没有从根本上解决)
Android游戏虚拟机算法JNI 尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完 ...
- IronJs 无相关源?
在工作中用到了IronJs 一切正常 就是 在启动项目的时候 报错说无相关源,将取消引用之后 就可以正常运行 如果不取消引用需要重新启动~ 是这个样子滴~ 说明: 在编译向该请求提供服务所需资源的过 ...
- zoj 3710 Friends
#include<stdio.h> #include<string.h> ][],h; int main(int argc, char* argv[]) { int t,i,n ...
- Vector(容器)
vector(容器)就像数组一样,但比数组强大很多,下面介绍一下vector常用的几种方法: 一.对于vector自身的处理,包括赋初始值,复制等等: vector<int> v1 ; v ...
- php开发中的一些常用统计的日期
<?php echo '<br>今天:<br>'; echo date("Y-m-d",strtotime("now")), &q ...
- Arduino 时钟模块(clock module) DS1306
http://www.pjrc.com/teensy/td_libs_DS1307RTC.html 下载相关的库程序 连接: DS1306: 1.接3.3V 2.SDA接A4 3.SCL接A5 读取: ...
- php mysql实现栏目分类递归
header("content-type:text/html;charset=utf-8"); $dbhost = "localhost"; // 数据库主 ...
- [LeetCode]题解(python):123-Best Time to Buy and Sell Stock III
题目来源: https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/ 题意分析: 和上题类似,array[i]代表第i天物品 ...
- JS 原型 & 继承
理解原型链 先看看http://www.ituring.com.cn/article/56184和http://www.cavabiao.com/prototype-and-inherit-of-ja ...
- 24_Core Data Demo
今天开始学习Core Data,类似于数据库,可以永久保存数据.不过当把App从iPhone删掉之后就没有了.可以用来保存App的运行数据. 参考链接:iOS Swift教程 Core Data 概述 ...