Friday, March 6, 2009

c++ stl - assigns value to every element of collection with fill

This time just a little tip about std::fill
//Author: Darius Kucinskas (c) 2008-2009
//Email: d[dot]kucinskas[eta]gmail[dot]com
//Blog: http://blog-of-darius.blogspot.com/
//License: GPL

#include <iostream>
#include <vector>
#include <iterator>

int main(){
    std::vector<int> vec;
    vec.resize(100);


    std::fill(vec.begin(), vec.end(), 123);
    std::copy(vec.begin(), vec.end(), 
      std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;
return 0; 
}