I was trying to sort a structure using stl sort in C++ . But i get some error . Is it that we cannot sort a structure in c++ using stl sort or is it my fault in implementation , if its my fault do let me know the correction .
Here's the code (its very small :) )
#include<iostream>
#include<algorithm>
using namespace std;
struct log {
int sd;
int ed;
} log[1000];
bool key(int i,int j) {
return (log[i].ed<log[j].ed);
}
int main() {
int n,i;
cin>>n;
sort(log,log+n,key);
for (i=0;i<n;i++) cin>>log[i].sd>>log[i].ed;
for (i=0;i<n;i++) cout<<log.sd<<","<<log.ed<<endl;
system("PAUSE");
}