今天研究迭代器时发现原来for循环可以这样写:
int my_array[5] = {1, 2, 3, 4, 5};
for (int &x : my_array)
{
cout<<x;
}
百度了一下才知道:C++11支持以范围为基础的 for 循环。看来又要多花点时间去掌握C++11的新特性了。
1.标准库所定义的迭代器不依赖于特定的容器,事实上C++还提供了另外三种迭代器:
*插入迭代器
*iostream迭代器
*反向迭代器
2.C++提供三种插入器
*back_inserter:使用push_back实现插入的迭代器
Constructs a back-insert iterator that inserts new elements at the end of x.
原型:
template <class Container>
back_insert_iterator<Container> back_inserter (Container& x);
int my_array[5] = {1, 2, 3, 4, 5};
for (int &x : my_array)
{
cout<<x;
}
百度了一下才知道:C++11支持以范围为基础的 for 循环。看来又要多花点时间去掌握C++11的新特性了。
1.标准库所定义的迭代器不依赖于特定的容器,事实上C++还提供了另外三种迭代器:
*插入迭代器
*iostream迭代器
*反向迭代器
2.C++提供三种插入器
*back_inserter:使用push_back实现插入的迭代器
Constructs a back-insert iterator that inserts new elements at the end of x.
原型:
template <class Container>
back_insert_iterator<Container> back_inserter (Container& x);