SirYakalot SirYakalot - 1 year ago 215
C++ Question

How do I reverse a C++ vector?

Is there a built-in vector function in C++ to reverse a vector in place?

Or do you just have to do it manually?

Answer Source

There's a function std::reverse in the algorithm header for this purpose.

#include <vector>
#include <algorithm>

int main() {
  std::vector<int> a;
  std::reverse(a.begin(), a.end());
  return 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download