01/10/2018, 09:59
Error File Binary in C++
include <iostream>
include <conio.h>
include <fstream>
include <windows.h>
using namespace std;
struct BXH
{
string NameGroup;
int thang,thua,hoa;
void nhap()
{
`cin.ignore();`
`cout<<"Nhap Ten Doi: "; getline(cin,NameGroup);`
`cout<<"So tran thang:"; cin>>thang;`
`cout<<"So tran thua :"; cin>>thua;`
`cout<<"So tran hoa :"; cin>>hoa;`
}`
void xuat()
{
`cout<<"Ten doi :"<<this->NameGroup<<endl;`
`cout<<"So tran thang :"<<this->thang<<endl;`
`cout<<"So tran thua :"<<this->thua<<endl;`
`cout<<"So tran hoa :"<<this->hoa<<endl;`
}
` int tinhDiem()
{
int diem = (thang*3 +hoa);
return diem;
}`
` operator= (BXH &bxh)
{
NameGroup = bxh.NameGroup;
thang = bxh.thang;
thua = bxh.thua;
hoa = bxh.hoa;
}
void friend swap1(BXH &a, BXH &b, BXH &temp)
{
temp = a;
a= b;
b= temp;
}
};`
`int main()`
`{`
` BXH *bxh,temp,vd;`
`int sodoi;`
`cout<<"Nhap so doi bong "; cin>>sodoi;`
`bxh = new BXH[sodoi];`
`for(int i=0;i<sodoi;i++)`
` {
(bxh+i)->nhap();
}`
` for(int i=0;i<sodoi-1;i++)
{
for(int j=1;j<sodoi;j++)
if((bxh+i)->tinhDiem() > ( bxh+j)->tinhDiem() )
{
swap1(*(bxh+i),*(bxh+j),temp);
}
}
system("cls");
ofstream ofs("File.dat",ios::binary|ios::out|ios::app);
ofs.write(reinterpret_cast<char*>(bxh),sizeof(BXH));
ofs.close();`
ifstream ifs("File.dat",ios::binary|ios::in);
ifs.read(reinterpret_cast<char*>(bxh),sizeof(BXH));
while(!ifs.eof())
{
if(!ifs.eof())
vd.xuat();
}
ifs.close();
return 0;
}
Bài liên quan