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;
}

 

相关文章:

  • 2021-07-04
  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-08
  • 2021-06-02
  • 2022-02-14
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案