C++11 定义:
iterator begin() noexcept;
const_iterator begin() const noexcept;
返回一个迭代器指向vector 第一个元素。
std::vector::cbegin
const_iterator cbegin() const noexcept;
作用类似于begin(),但不能修改迭代器的内容。
// vector::cbegin/cend
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector = {10,20,30,40,50};
std::cout << "myvector contains:";
for (auto it = myvector.cbegin(); it != myvector.cend(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
Output:
myvector contains: 10 20 30 40 50 |