0
如何顛倒矢量?我已經閱讀了很多在線文章,但我無法找到一個使用名稱空間標準。我需要使用reverse()和vect.reverse(); 這裏是我的代碼:顛倒矢量並打印它
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main()
{
cout << "Kaitlin Stevers" << endl;
cout << "Exercise 11 - Vectors" << endl;
cout << "November 12, 2016" <<endl;
cout << endl;
cout << endl;
int size;
cout << " How many numbers would you like the vector to hold? " << endl;
cin >> size;
vector<int> numbers;
int bnumbers;
for (int count = 0; count < size; count++)
{
cout << "Enter a number: " << endl;
cin >> bnumbers;
numbers.push_back(bnumbers); // Adds an element to numbers
}
//display the numbers stored in order
cout << "The numbers in order are: " << endl;
for(int bcount = 0; bcount < size; bcount++)
{
cout << numbers[bcount] << " ";
}
cout << endl;
//display the numbers stored reversed
reverse(numbers.begin(), numbers.end());
return 0;
}