Katie Stevers Katie Stevers - 27 days ago 9
C++ Question

Error message/Vector of user input numbers

Here is the error I am getting:
Exercise11.cxx:29:13: error: invalid operands to binary expression ('ostream' (aka 'basic_ostream') and 'vector')

#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);
}
//display the numbers stored in order
cout << "The numbers in order are: " << endl;
for(int i=0; i < size; i++)
{
cout<<numbers[i]<< " ";
}
cout << endl;
return 0;
}


The error comes up on the part of the code that says:

cout << numbers << endl;


Second question:

How do I use vent.reverse(); to reverse the vector and then display it.

Answer

You have to use a loop to print the vector:

for(int i=0; i < size; i++){
    cout<<numbers[i]<< " ";
}