I have got the following code:
#include <iostream>
#include <vector>
using namespace std;
vector<int> Reversed(const vector<int>& v){
//vector<int> v; //[Error] declaration of 'std::vector<int> v' shadows a parameter
int z; vector<int> copy; vector<int> working;
working = v;
z = working.size();
int i;
for (i = 0; i<=z; i++){
working[i] = working[z];
copy.push_back(working[i]);
}
return copy;
}
int main() {
vector<int> v;
cin >> v; /*[Error] no match for 'operator>>' (operand types are 'std::istream'
{aka 'std::basic_istream<char>'} and 'std::vector<int>')*/
cout << Reversed(v);
return 0;
}
Please, explain to me why I am getting this error on line 18:
no match for operator >>`
P.s.: const & i
is a prerequisite task, I cannot change it. I just need an upside-down copy of this vector.
It looks like you are asking the user to enter a list of numbers.
std::cin
(or justcin
, since you've gotuse namespace std;
) doesn't know how to receive a list of integers and turn that into avector<int>
for you.If you want to receive a vector from user input, I would suggest you ask the user for a list of numbers, something like: