c++ - no matching function for call to sort() -


i'm teaching myself through programming: principles , practice using c++ (2nd edition) , i'm @ vectors section. can copy , paste code , still won't work. code follows.

#include "iostream" #include "vector" #include "algorithm"    using namespace std;   int main() {     cout << "please enter temperatures last 5 days\n";     vector<double> temperatures;      for(double temp; cin >> temp;){         temperatures.push_back(temp);     }     double sum = 0;     (double temp : temperatures){         sum += temp;     }     cout << "mean temperature " <<(sum / temperatures.size()) << endl;      sort(temperatures);     cout << "median temperature " << temperatures[temperatures.size()/2]; } 

help appreciated , explanation better.

template function std::sort expects pair of iterators arguments (i.e. range) and, optionally, comparator. there's no sort function can applied directly container. did idea call sort(temperatures)? sort entire temperatures vector should called std::sort(temperatures.begin(), temperatures.end()). i'm sure book has quite few examples demonstrate rather clearly.

additionally, standard library headers should included #include <algorithm>, i.e. using <...> syntax, not "..." syntax.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -