array::cbegin
傳回 const 隨機存取 Iterator 至容器 (Container) 中的第一個項目。
const_iterator cbegin() const;
傳回值
解決const隨機存取Iterator第一個項目 array Class (TR1) 是成功或空的 array的位置。您一定要比較之值傳回 array::cend 或確定自己的 array::end 是有效的。
備註
array::cbegin的傳回值,因此無法修改 array 物件。
範例
// array_cbegin.cpp
// compile with: /EHsc
#include <array>
#include <iostream>
int main()
{
using namespace std;
array<int, 2> c1 = {1, 2};
array<int, 2>::const_iterator c1_Iter;
cout << "The array c1 contains elements:";
c1_Iter = c1.cbegin();
for (; c1_Iter != c1.cend(); c1_Iter++)
{
cout << " " << *c1_Iter;
}
cout << endl;
// The following line would be an error because iterator is const
// *c1.cbegin() = 200;
}
需求
標題: <array>
命名空間: std