各位大佬求助 我是小白 请多指教我谢谢
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <memory.h>
using namespace std;
struct billion
{
int no;
char name[20];
char account[6];
int age;
char company[20];
char country[20];
};
ostream& operator<<(ostream& os, billion &b)
{
os << "编号" << '\t' << "姓名" << "\t\t" << "国家" << "\t\t" << "公司" << '\t' << "年龄" << '\t' << "资产" << endl;
os << b.no << '\t' << b.name << '\t' << b.country << '\t' << << '\t' << b.age << '\t' << b.account << endl;
return os;
}
class find_billion
{
private:
billion b;
char* country;
int min;
int max;
public:
find_billion()
{
memset(this->country, NULL, sizeof(this->country));
min = 0;
max = 0;
}
find_billion(char *country, int min, int max)
{
this->country = country;
this->min = min;
this->max = max;
}
void operator()(billion b)
{
if (b.age > min && b.age < max && !strcmp(b.country, country))
{
cout << b << endl;
}
}
};
int main()
{
ifstream in;
in.open("d:\\billion.bin");
vector<billion>v;
billion b;
in.read((char *)&b, sizeof(billion));
while (!in.eof())
{
in.read((char *)&b, sizeof(billion));
v.push_back(b);
}
find_billion bil = for_each(v.begin(), v.end(), find_billion("China", 60, 70));
in.close();
return 0;
}