the difference between : cbegin(cend) and begin(end)
来源:互联网 发布:三维坐标测量仪软件 编辑:程序博客网 时间:2024/05/10 00:22
cbegin(cend):
A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like theiterator returned by vector::begin, but it cannot be used to modify the contents it points to, even if the vector object is not itself const.
If the container is empty, the returned iterator value shall not be dereferenced.
begin(end):
Additional topics for the begin and end:
When the article say the begin() function in the array, we should get more attention on the begin function.. It says it's a function in the concept of "array", not the member-fucntion for the iterator.
I found there is another point we need to know.. The books don't mention it. for a instance:
#include <iostream>
#include <iterator>
using name space;
int main()
{
int ia[] = {0,1,2,3,4,5,6,7,8,9}; // ten elements in the array
int *pbeg = begin(ia);
int *pend = end(ia):
cout << *pbeg << " " << *pend << endl;
}
if you print them, what does your comipler tell u ? The gcc compiler told me: 0,0. The *pend doesn't point to the last element in array. why?
Let's make some change for it?
#include <iostream>
#include <iterator>
using name space;
int main()
{
int ia[] = {0,1,2,3,4,5,6,7,8,9}; // ten elements in the array
int *pbeg = begin(ia);
int *pend = end(ia):
cout << *pbeg << " " << *pend << endl;
for (unsigned int i = 0; i != 11; ++i) // special purpose for the error..
cout << *(pbeg+i) << " |";
Check it out? Holly crap, the *pend had been changed, the undefined ia[11] is same as the *pend... What's that???
*pend pointer is stranger than I had know. But right now, i see it .
the safe usage is *(pend-1) replace the *pend.... At least , we need more thinking when we programing...
- the difference between : cbegin(cend) and begin(end)
- The difference between (()) and ().
- the difference between "./" and "sh"
- Difference between End-to-end testing and System testing
- cbegin(), cend() demo
- the difference between the SOURCELIBS and TARGETLIBS
- The difference between Const and ReadOnly
- The difference between Failure and Success
- The difference between Process and Procedure
- The difference between GetDC and GetWindowDC
- The difference between Chinese and American
- The difference between J2ee and Ruby
- The difference between SendMessage and PostMessage
- The difference between lint and gcc
- The difference between sizeof and strlen
- The Difference Between Internet, Intranet, and Extranet
- The difference between CLOCK_MONOTONIC and CLOCK_REALTIME
- The difference between UTF8 and AL32UTF8
- 情绪ABC理论的案例分析,呵呵
- 各类C++/C程序员面试题
- 17--2--14字符串比较
- 职场规则
- Android中Bitmap、Drawable、byte[]转换
- the difference between : cbegin(cend) and begin(end)
- 如何记录MySQL执行过的SQL语句?
- 网桥的工作原理与应用
- MySQL 学习笔记 一
- Jdom解析xml过程详解
- arm在uboot上跑裸程序
- Sublime Text下配置SublimeLinter进行PHP代码检查
- 17--2--15先自己输入字符串再求长度
- 一网打尽2013最常用的NoSQL数据库