struct gydytojas {
int gydid, amzius, specialyb, telefonas, asmkod;
String vardas;
String pavarde;
String adresas;
friend ostream& operator<<(ostream& os, const gydytojas& obj)
{
os << obj.vardas.c_str()
<< obj.pavarde.c_str()
<< obj.adresas.c_str()
<< obj.gydid
<< obj.amzius
<< obj.specialyb
<< obj.telefonas
<< obj.asmkod;
// Print the members to os like you would to cout
return os;
};
friend fstream& operator>>(fstream& fs, const gydytojas& obj)
{
fs >> obj.vardas.c_str();
>> obj.pavarde.c_str();
>> obj.adresas.c_str();
>> obj.gydid;
>> obj.amzius;
>> obj.specialyb;
>> obj.telefonas;
>> obj.asmkod;
// reading code
return fs;
};
};
gydytojas gydmas[100];
This code is in unit1.h
gydytojas pgyd;
pgyd.vardas=Edit21->Text;
pgyd.pavarde=Edit22->Text;
pgyd.adresas=Edit24->Text;
pgyd.asmkod=StrToInt(Edit23->Text);
pgyd.amzius=StrToInt(Edit27->Text);
pgyd.gydid=StrToInt(Edit26->Text);
pgyd.telefonas=StrToInt(Edit25->Text);
pgyd.specialyb=ComboBox5->ItemIndex;
bool pagalb = false;
int j=1;
fstream kd("Gydytojai.sed");
while (!kd.eof()) // Checking if the entry already exist;
{ if (gydmas[j].vardas==pgyd.vardas) {ShowMessage(L"Gydytojo id jau egzistuoja");
pagalb=true;}; // if the entry exist, variable pagalb becomes true
j++;};
kd.close();
ofstream fr("Gydytojai.sed");
if (pagalb==false) {gydmas[j+1]=pgyd; fr << gydmas[j+1];};
// if variable pagalb false, then the structure gydytojas is written to file as array
fr.close();
This code is unit1.cpp, as you see, im trying to search the exact id from the fields, which are written, but now i got the project error message. Before that, gydytojas.vardas field hasn't been recognized in code, so all the information was always written to file. Any suggestion why i get error message, and what way would be better?