How to assign N numbers with the same value to a vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
 
int main ()
{
    std::vector<int> v;
    
    v.assign(5, 99); 
    
    for (auto const &n: v) {
        std::cout << n << " ";
    }
  
    return 0;
}
  
  
  
/*
run:
  
99 99 99 99 99 
   
*/

 



answered Dec 6, 2020 by avibootz
...