I am trying to take integer input in a vector but the following error keeps on coming.
error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'std::vector<int>')|
#include <iostream>
#include <vector>
int Max(std::vector<int> v){
int max1=0, max2=0;
int index1 = 0;
int n = v.size();
for(int i = 0; i < n; i++){
if(v[i] > max1){
max1 = v[i];
index1 = i;
}
}
for(int i = 0; i < n; i++){
if(i != index1 && v[i] > max2){
max2 = v[i];
}
}
return max2*max1;
}
int main(){
int n = 0;
int result = 0;
std::cin >> n;
std::vector<int> v[n];
for(int i = 0; i < n; i++){
std::cin >> v[i];
}
result = Max(v);
std::cout << result;
It takes a while before learning how to interpret the error messages. In this case you could have questioned why it thinks v[i] is a std::vector<int> and come to the conclusion that there is probably something wrong with the declaration of v. I'm not saying this to criticize, only to help.