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

后端 未结 10 876
[愿得一人]
[愿得一人] 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:09

    I don't know of a way to do it like in python but another alternative is obviously to for loop through it:

    for (int i = range1; i < range2; ++i) {
        x.push_back(i);
    }
    

    chris's answer is better though if you have c++11

提交回复
热议问题