Neatest way to loop over a range of integers

后端 未结 4 1288
感情败类
感情败类 2020-12-17 07:28

Since C++11 introduced the range-based for loop (range-based for in c++11), what is the neatest way to express looping over a range of integers?

Instead of

4条回答
  •  借酒劲吻你
    2020-12-17 08:22

    The neatest way is still this:

    for (int i=0; i

    I guess you can do this, but I wouldn't call it so neat:

    #include 
    
    int main()
    {
      for ( auto i : { 1,2,3,4,5 } )
      {
        std::cout<

提交回复
热议问题