Friday, 21 April 2017

c++ - My program keeps throwing compilation error,I am not able to figure out why the error has occured

Answer


Can't seem to figure out the error that the program keeps throwing.The program keeps throwing the error when I am dereferencing an iterator.Could anyone tell me where did I go wrong?
The problem for the code goes like this "Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers."



void miniMaxSum(vector arr) {   //arr = {1,2,3,4,5}
int sum = 0;
unordered_map results;

for(size_t i = 0;i < arr.size();i++)
{
results[arr[i]] = accumulate(arr.begin(),arr.end(),sum) - arr[i];
}
pair::iterator,unordered_map::iterator> mn;
mn = minmax_element(results.begin(),results.end());
cout<< *mn.first<<" "<<*mn.second; //line where the error is occuring
}



Solution.cpp: In function 'void miniMaxSum(std::vector)':
Solution.cpp:9:9: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream'} and 'std::pair')
cout<< *mn.first<<" "<<*mn.second;
~~~~^~~~~~~~~~~~

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...