How to initialize a vector with another vector in c++

1 Answer

0 votes
#include <iostream>
#include <vector>
  
int main ()
{
    std::vector<int> v1 = { 5, 2, 7, 1, 9, 4 };
 
    std::vector<int> v2(v1.begin(), v1.end());

    for (auto n: v2) {
        std::cout << n << " ";
    }
   
    return 0;
}
   
   
   
   
/*
run:
 
5 2 7 1 9 4 
    
*/

 

 



answered Dec 6, 2020 by avibootz

Related questions

1 answer 141 views
2 answers 117 views
1 answer 186 views
1 answer 196 views
2 answers 241 views
241 views asked Apr 28, 2018 by avibootz
...