Is there a compact equivalent to Python range() in C++/STL

后端 未结 10 891
[愿得一人]
[愿得一人] 2020-12-04 21:23

How can I do the equivalent of the following using C++/STL? I want to fill a std::vector with a range of values [min, max).

# Python
>>>         


        
10条回答
  •  感动是毒
    2020-12-04 22:10

    In C++11, there's std::iota:

    #include 
    #include  //std::iota
    
    std::vector x(10);
    std::iota(std::begin(x), std::end(x), 0); //0 is the starting number
    

提交回复
热议问题