下面是我的源代码,按compile按钮时可以完成,再按build按钮时就会在下面的窗口出现Linking......
然后就一直停在那儿了,选择停止构件它也不会停下,机子也没有死,用任务管理器可以强行关闭
VC,但是它就是一直停在那没反应了.
#include<iomanip.h>
#include<stdlib.h>
#include<fstream.h>
class PublicDate //文件为只读文件,非拥有特权不能修改;
{
protected:
char name[101];
long id;
public:
char * seekName(long,int); //返回名称(拼音方式);
void set(int); //1为民族,2为学院,3为班级,4为专业;
void display(int); //同上;
void setup(int); //同上;
void read(ifstream &); //按顺序依次读入;
void write(ofstream &); //按顺序依次写入;
void add(int);
};
void openFileg(ifstream & g,int i) //选择性打开输入流文件;
{
switch(i)
{
case 1:g.open("public_minzhu.dat",ios::nocreate);break;
case 2:g.open("public_class.dat",ios::nocreate);break;
case 3:g.open("public_college.dat",ios::nocreate);break;
case 4:g.open("public_zhuanye.dat",ios::nocreate);break;
}
if(g.fail())
{
cout<<"文件无法打开"<<endl;
exit(1);
}
}
void openFilep(ofstream & p,int i) //选择性打开输入流文件;
{
switch(i)
{
case 1:p.open("public_minzhu.dat",ios::app);break;
case 2:p.open("public_class.dat",ios::app);break;
case 3:p.open("public_college.dat",ios::app);break;
case 4:p.open("public_zhuanye.dat",ios::app);break;
}
if(p.fail())
{
cout<<"文件无法打开"<<endl;
exit(1);
}
}
char * PublicDate::seekName(long idOfName,int i)
{
ifstream get;
openFileg(get,i);
do
{
if(get.eof())
break;
read(get);
}while(id!=idOfName);
if(id==idOfName)
{
return name;
}
return NULL;
get.close();
}
void PublicDate::set(int i)
{
switch(i)
{
case 1:cout<<"请输入民族(注:以拼音方式输入)"<<endl;break;
case 2:cout<<"请输入班级(注:以拼音方式输入)"<<endl;break;
case 3:cout<<"请输入学院(注:以拼音方式输入)"<<endl;break;
case 4:cout<<"请输入专业(注:以拼音方式输入)"<<endl;break;
}
cin>>name;
cout<<"请输入编号"<<endl;
cin>>id;
}
void PublicDate::display(int i)
{
ifstream get;
openFileg(get,i);
while(!get.eof())
{
read(get);
cout<<id<<" "<<name<<endl;
}
get.close();
}
void PublicDate::setup(int i)
{
char c='y';
ofstream put;
openFilep(put,i);
while(c=='y')
{
set(i);
write(put);
cout<<"是否继续?y/n"<<endl;
cin>>c;
}
put.close();
}
void PublicDate::read(ifstream & g)
{
g>>name>>id;
}
void PublicDate::write(ofstream & p)
{
p<<setw(101)<<name<<setw(12)<<id;
}
void PublicDate::add(int i)
{
char c='y';
ofstream put;
openFilep(put,i);
while(c=='y')
{
set(i);
write(put);
cout<<"是否继续?y/n"<<endl;
cin>>c;
}
put.close();
}
void seekID(PublicDate & p)
{
int i;
long l;
char c='y';
while(c=='y')
{
cout<<"请输入查询类型:1为民族编号,2为班级编号,3为学院编号,4为专业编号,5返回上一级菜单"<<endl;
cin>>i;
if(i==5)
return;
cout<<"请输入编号"<<endl;
cin>>l;
cout<<"查询结果:"<<l<<" "<<p.seekName(l,i)<<endl;
cout<<"是否继续?y/n"<<endl;
cin>>c;
}
}
void addRecord(PublicDate & p)
{
int i;
cout<<"请选择增加记录类型:1为民族类记录,2为班级类记录,3为学院类记录,4为专业类记录,5返回上一级菜单"<<endl;
cin>>i;
if(i==5)
return;
p.add(i);
}
void displayAll(PublicDate & p)
{
int i;
cout<<"请选择输出记录类型:1为民族类记录,2为班级类记录,3为学院类记录,4为专业类记录,5返回上一级菜单"<<endl;
cin>>i;
if(i==5)
return;
p.display(i);
}
void main()
{
PublicDate P;
int n=4;
char c='y';
while(c=='y')
{
cout<<"请选择任务:1.查看记录,2.查询记录,3.增加记录,4.退出程序"<<endl;
cin>>n;
switch(n)
{
case 1:displayAll(P);break;
case 2:seekID(P);break;
case 3:addRecord(P);break;
case 4:goto s;
}
cout<<"是否继续?y/n"<<endl;
cin>>c;
}
s:
cout<<"感谢您的使用"<<endl;
}