我通过他们的年龄要那么样的名字排序名称
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct Person{
std::string name;
int age;
};
struct by_age{
bool operator() (Person const &a,Person const &b){
return a.age>b.age;
}
};
int main(){
vector<Person>people;
for (int i=0;i<4;i++){
cin>>people[i].age>>people[i].name;
}
sort(people.begin(),people.end(),by_age());
for (int i=0;i<4;i++){
cout<<people[i].name<<people[i].age<<" ";
}
return 0;
}
但是这个代码有很多错误,请帮忙 看看这个网站
C++ STL: Custom sorting one vector based on contents of another
这个程序有什么错误?预期的产出是多少,产量是多少?您是否尝试过附加调试器来查看代码出错的位置? “这是我的代码,请修复它”在Stack OVerflow中不是一个合适的问题;试着按照“我试图做X,但是当我用输入Y运行它时,我意外地得到了结果Z;我认为它可能与W有关。 – 2010-09-24 15:32:38