65,210
社区成员
发帖
与我相关
我的任务
分享
void Reserve::Add() //订房
{
ofstream ofs("d:\\hotel system.txt", ios::out | ios::app);
if (ofs.is_open())
{
Reserve e;
cout << "--------------------------------------------" << endl;
cout << "请输入订房人数: " << endl;
int addnum = 0;
cin >> addnum;
cout << "请输入入住者的姓名、身份证号、入住日期、所订房型:" << endl;
for (int j = 0; j < addnum; j++)
{
cin >> e;
ofs << e;
}
ofs.close();
}
void Reserve::show() //查看订房记录
{
fstream fd("d:\\Hotel system.txt", ios::in);
int ch;//定义一个字符
ch = fd.get();//从文件中读取一个字符
if (ch == EOF)//如果一个字符都没读取到,表示文件为空的
{
cout << "空白文件,无法读取!" << endl;
}
else
{
cout << "--------------------------------------------" << endl;
cout << " 姓名\t" << "身份证号\t" << "入住日期\t"<<"所订房型" << endl;
int n = 0; string str;
Reserve *e = new Reserve[50];
while(getline(fd,str))
{
cout << " ";
cout<<str<<endl;
}
fd.close();
}
}