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

1 Answer

0 votes
#include <iostream>
#include <list>

void printList(std::list<int> const &l) {
    for (auto const &n: l) {
        std::cout << n << " ";
    }
}

int main() {
    std::list<int> l;
    int N = 5, value = 100;
    
    l.assign(N, value);   

    printList(l);
    
    return 0;
}



/*
run:

100 100 100 100 100 

*/

 



answered Apr 11, 2020 by avibootz

Related questions

...