题目:
假设有一个工人类,形式如下:
class Worker{
char name[10];
int age;
double salary;
public:
Worker(...)
void setData(char *Name,int Age,double wage)
void display();//显示各数据成员的值
......
};
完成该类的设计,并用STL中的链表list管理该类的对象,并按姓名进行排序,然后输出链表中的每个对象
实现代码:
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
void main()
{
ifstream in;
in.open("C:\\Users\\DELL\\Desktop\\1.txt",ios::in);
ofstream out;
out.open("C:\\Users\\DELL\\Desktop\\2.txt", ios::in);
string l;
string c;
if (in)
{
while (getline(in, l))
{
cout << l << endl;
c = c + l + '\n';
out << l << endl;
}
cout << c;
out << c;
}
else
{
cout << "no such file" << endl;
}
in.close();
out.close();
}