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 237 views
1 answer 278 views
1 answer 133 views
1 answer 196 views
1 answer 174 views
...