Hi Everyone,
I have a C++ program lesson, but i can't to do it. I have a binary file with structured datas.
I have to read the datas, and take into a class (structure array).
Here is my code:
#include <iostream>
#include <fstream>
using namespace std;
struct dolgozo
{
char nev[30];
unsigned int kor;
long int fizetes;
};
class dolgoszt
{
private:
dolgozo *adatok;
int db;
public:
dolgoszt(char nev[])
{
int i=0;
db=0;
dolgozo r;
ifstream zh;
zh.open(nev);
if (zh.fail()) {cout<<"Error when open the file";exit(1);}
zh.read((char*) &r, sizeof(dolgozo));
while (!zh.eof())
{
db++;
}
adatok = new dolgozo[db];
zh.beg;
zh.read((char*) &r, sizeof(dolgozo));
while (!zh.eof())
{
adatok[i]=r;
i++;
zh.read((char*) &r, sizeof(dolgozo));
}
zh.close();
}
~dolgoszt();
void kiir()
{
cout<<adatok->nev<<"\t"<<adatok->fizetes<<"\t"<<adatok->kor<<endl;
}
};
int main()
{
char file[30]="c:\\dolgozo.dat";
dolgoszt d(file);
cin.get();
}
But i can't compile this, i have some fatal error
I think this part has the problem :(
adatok = new dolgozo[db];
zh.beg;
zh.read((char*) &r, sizeof(dolgozo));
while (!zh.eof())
{
adatok[i]=r;
i++;
zh.read((char*) &r, sizeof(dolgozo));
}
I attached the binary file. Please help me. I am new in C++, i can programming in Visual Basic, but it is very hard to learn C++