Printing vector in reverse order

后端 未结 5 1316
粉色の甜心
粉色の甜心 2021-01-21 22:34

Is there a better way of printing a vector in reverse order then this:

#include
#include
#include
using namespace          


        
5条回答
  •  情深已故
    2021-01-21 23:27

    There are many ways to print a bidirectional sequence in reverse without reversing the elements, e.g.:

    std::copy(vec.rbegin(), vec.rend(), std::ostream_iterator(std::cout, "\n"));
    std::reverse_copy(vec.begin(), vec.end(), std::ostream_iterator(std::cout, "\n"));
    

提交回复
热议问题