How to get an iterator to the beginning of a vector in C++

2 Answers

0 votes
#include <iostream>
#include <vector>
 
int main() 
{
    std::vector<int> v = { 5, 7, 3, 1, 9 };
 
    std::cout << *(std::begin(v));
}
 
 

 
/*
run:
 
5
 
*/

 



answered Jun 21, 2020 by avibootz
0 votes
#include <iostream>
#include <vector>
 
int main() 
{
    std::vector<int> v = { 5, 7, 3, 1, 9 };
 
    auto vb = std::begin(v);
    
    std::cout << *vb;
}
 
 

 
/*
run:
 
5
 
*/

 



answered Jun 21, 2020 by avibootz

Related questions

2 answers 229 views
1 answer 272 views
1 answer 129 views
1 answer 189 views
1 answer 164 views
...