我正在尝试一个文件处理程序来输入记录,而在另一个程序中尝试删除一条记录。我似乎得到了这个错误 -
没有匹配函数来调用`std :: basic_fstream> :: open(const char [8],bool)'
对于每个f.open语句都有一个ios :: binary声明。
这是代码
这个用于输入记录
#include<iostream.h>
#include<fstream.h>
class employee
{
int code;
char name[20];
char desig[15];
float salary;
public: void get_emp();
};
void employee:: get_emp()
{
cout<<"Code--> ";
fflush(stdin);
cin>>code;
cout<<"Name--> ";
fflush(stdin);
gets(name);
cout<<"Designation--> ";
fflush(stdin);
gets(desig);
cout<<"Salary--> ";
fflush(stdin);
cin>>salary;
}
int main()
{
fstream f;
char ch;
f.open("EMP.dat", ios::binary||ios::app);
employee emp;
cout<<"Enter data:\n";
do
{
emp.get_emp();
f.write((char*)&emp,sizeof(emp));
cout<<"Entre more???(y/n)";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
f.close();
system("pause>null");
return 0;
}
这是为了删除记录
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
struct employee
{
int code;
char name[20];
char desig[15];
float salary;
}emp;
int main()
{
int xcode; //temporary declaration for employee code
int flag = 0;
fstream ef, tf;
//ef opened for reading, tf opened for transferring all records including modified record
ef.open("EMP.dat", ios::binary|| ios::in);
tf.open("TEMP.dat", ios::binary|| ios::out);
cout<<"Enter employee code to delete:";
cin>>xcode;
while(ef)
{
if(!ef)
exit(0);
ef.read((char*)&emp, sizeof(emp));
if(emp.code == xcode)
{
flag = 1;
}
else
tf.write((char*)&emp, sizeof(emp));
}
ef.close();
tf.close();
if(flag == 1)
cout<<"Record deleted.";
else
cout<<"Not found.";
fstream xf, yf;
//tf opened for reading
xf.open("TEMP.dat", ios::binary||ios::in);
//ef opened for copying all records from TEMP.dat
yf.open("EMP.dat",ios::binary||ios::out);
while(xf)
{
if(!xf)
exit(0);
xf.read((char*)&emp, sizeof(emp));
yf.write((char*)&emp, sizeof(emp));
}
xf.close();
yf.close();
system("pause");
return 0;
}
请帮忙。我的考试需要它。
谢谢
答案 0 :(得分:3)
按位OR是单个管道(|),而不是双管道。