c++ stl algorithm: std::fill, std::fill_n

std::fill

    在[first, last)范围内填充值

#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    std::vector<int> v;
    v.resize(10);
    std::fill(v.begin(), v.end(), 100);
    return 0;
}

std::fill_n

    在[fist, fist + count)范围内填充值

#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    std::vector<int> v;
    v.resize(10);
    std::fill_n(v.begin(), 5, 100);
    std::fill_n(v.begin() + 5, 5, 200);
    return 0;
}
原文地址:https://www.cnblogs.com/lanye/p/3736447.html