I'm reading in a list of names and I want to order the last names by which comes first alphabetically. the file will contain contents like this
Smith John 467-604-4535
Kidd Jason 433-243-5252
etc
class record
{
bool operator <(const record &rhs) const
{
return (lastname < rhs.lastname)
}
private:
string fn, ln, pn;
};
int main(int argc, char *argv[])
{
record data;
ifstream fs;
fs.open(arg2.c_str());
vector<record> vec;
while (fs >> data)
{
vec.push_back(data);
}
fs.close();
sort (vec.begin(), vec.end(), data);
for (int i=0; i < vec.size(); i++)
cout << vec[i];
}
The line of code that is giving me the error is the sort (vec.begin(), vec.end(), data) It's giving me a ton of errors. Everything else from my knowledge is working though. It's just sort. Any ideas what is wrong with the sort? How can I sort the vector?
std::sort, neither of which takes an object of type T as a third paramenter. Just usesort(vec.begin(), vec.end());