您的位置:首页 > 其它

vector::begin

2016-07-23 12:39 239 查看
Return iterator to beginning
Returns an iterator pointing to the first element in the vector.

Notice that, unlike member vector::front, which returns a reference to the first element, this function returns arandom
access iterator pointing to it.

If the container is empty, the returned iterator value shall not be dereferenced.


Parameters(参数)

none


Return Value

An iterator to the beginning of the sequence container.

If the vector object is const-qualified, the function returns a const_iterator. Otherwise, it returns an iterator.

Member types iterator and const_iterator are random access iterator types
(pointing to an element and to a const element, respectively).

// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
for (int i=1; i<=5; i++) myvector.push_back(i);

cout << "myvector contains:";
for (vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
cout << ' ' << *it;
cout << endl;
return 0;
}


---------------------------------------------------

// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
vector<int> myvector;
for (int i=1; i<=5; i++) myvector.push_back(i);

cout << "myvector contains:";
vector<int>::iterator it;

for (it = myvector.begin() ; it != myvector.end(); ++it)
cout << ' ' << *it;
cout << endl;
return 0;
}

Output:

myvector contains: 1 2 3 4 5

----------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: