#include <iostream>
#include <fstream>
using namespace std;
struct Book
{
char no[11];
char name[21];
int page;
};
int load_file(Book book[], int &n);
int save_file(Book book[], int n);
void input(Book book[], int &n);
void display(Book book[], int n);
void gotoxy(int x, int y);
int main()
{
int sel; Book book[1000]; int n = 0;
while (1)
{
system("cls");
cout << " 1------导入图书信息 ";
cout << " 2------输入图书信息 ";
cout << " 3------浏览图书信息 ";
cout << " 0------退出系统 ";
cout << " 选择: ";
cin >> sel;
switch (sel)
{
case 1: load_file(book, n); break;
case 2: input(book, n); break;
case 3: display(book, n); break;
case 0: save_file(book, n); break;
}
if (sel == 0) { cout << " 系统结束,再见!"; return 0; }
}
}
int load_file(Book book[], int &n)
{
ifstream infile;
Book newbook;
infile.open("data.txt", ios::in);
if (!infile)
{
cout << "无数据文件data.txt!";
n = 0;
return 0;
}
while (!infile.eof())
{
infile >> newbook.no >> newbook.name >> newbook.page;
if (infile)
{
book[n] = newbook; n++;
}
else
break;
}
infile.close();
return n;
}
int save_file(Book book[], int n)
{
ofstream outfile;
outfile.open("data.txt", ios::out);
if (!outfile)
{
cout << "无法将数据保存到文件data.txt!";
return 0;
}
int i;
for (i = 0; i<n; i++)
{
outfile << book[i].no << " " << book[i].name << " " << book[i].page
<< endl;
}
outfile.close();
return 1;
}
void input(Book book[], int &n)
{
Book newbook;
do
{
system("cls");
cout << "书名(输入0时结束输入)";
cin >> newbook.no;
if (strcmp(newbook.no, "0") == 0)
return;
cout << "作者:"; cin >> newbook.name;
cout << "页数:";
cin >> newbook.page;
cout << "确认(y/n)?";
char yn;
cin >> yn;
if (yn == 'Y' || yn == 'y')
{
book[n] = newbook; n++;
}
} while (1);
return;
}
void display(Book book[], int n)
{
if (n == 0)
{
cout << "无数据!";
system("pause");
return;
}
int i;
for (i = 0; i<n; i++)
{
cout << book[i].no << " " << book[i].name << " " << book[i].page
<< endl;
}
system("pause");
}
在调试窗口中选择3时,图书信息会闪烁后回到目录是什么情况