008
08.03.2005, 18:19 Uhr
Oliver
S2-Pixelgeneral
|
So hab's umgeschrieben, stürzt aber immernoch ab . Ich hab 2 Funktionen Load und Save. Wenn getline[...] kommt, passiert es.
C++: |
bool Geraete_DB::Load() { ifstream ifs("gp_db.bin",ios::binary); unsigned Anz_Plaetze; unsigned Anzahl_Geraete;
if(!ifs) return 0;
ifs.read((char*)&Anz_Plaetze,sizeof(unsigned));
for(unsigned i=0;i<Anz_Plaetze;++i) { getline(ifs,m_vPlaetze[i].m_sName,'\0'); getline(ifs,m_vPlaetze[i].m_sInhaber,'\0'); getline(ifs,m_vPlaetze[i].m_sStrasse,'\0'); getline(ifs,m_vPlaetze[i].m_sAdresse,'\0'); getline(ifs,m_vPlaetze[i].m_sSteuernummer,'\0'); getline(ifs,m_vPlaetze[i].m_sPlatzNummer,'\0');
ifs.read((char*)&Anzahl_Geraete,sizeof(unsigned));
for(unsigned z=0;z<Anzahl_Geraete;++z) { getline(ifs,m_vPlaetze[i].m_vGeraete[z].m_sGeraeteBezeichnung,'\0'); ifs.read((char*)&m_vPlaetze[i].m_vGeraete[z].m_uGeraeteNummer,sizeof(unsigned)); ifs.read((char*)&m_vPlaetze[i].m_vGeraete[z].m_uMWSteuer,sizeof(unsigned char)); ifs.read((char*)&m_vPlaetze[i].m_vGeraete[z].m_uProzent,sizeof(unsigned char)); } }
ifs.close();
return 1; }
void Geraete_DB::Save() { ofstream ofs("gp_db.bin",ios::binary);
unsigned Anzahl_Geraete; unsigned Anz_Plaetze
Anz_Plaetze=m_vPlaetze.size(); ofs.write((char*)&Anz_Plaetze,sizeof(unsigned));
for(unsigned i=0;i<Anz_Plaetze;++i) { ofs.write(m_vPlaetze[i].m_sName.c_str(),m_vPlaetze[i].m_sName.length()+1); ofs.write(m_vPlaetze[i].m_sInhaber.c_str(),m_vPlaetze[i].m_sInhaber.length()+1); ofs.write(m_vPlaetze[i].m_sStrasse.c_str(),m_vPlaetze[i].m_sStrasse.length()+1); ofs.write(m_vPlaetze[i].m_sAdresse.c_str(),m_vPlaetze[i].m_sAdresse.length()+1); ofs.write(m_vPlaetze[i].m_sSteuernummer.c_str(),m_vPlaetze[i].m_sSteuernummer.length()+1); ofs.write(m_vPlaetze[i].m_sPlatzNummer.c_str(),m_vPlaetze[i].m_sPlatzNummer.length()+1);
Anzahl_Geraete=m_vPlaetze[i].m_vGeraete.size(); ofs.write((char*)&Anzahl_Geraete,sizeof(unsigned));
for(unsigned z=0;z<Anzahl_Geraete;++z) { ofs.write(m_vPlaetze[i].m_vGeraete[z].m_sGeraeteBezeichnung.c_str(),m_vPlaetze[i].m_vGeraete[z].m_sGeraeteBezeichnung.length()+1); ofs.write((char*)&m_vPlaetze[i].m_vGeraete[z].m_uGeraeteNummer,sizeof(unsigned)); ofs.write((char*)&m_vPlaetze[i].m_vGeraete[z].m_uMWSteuer,sizeof(unsigned char)); ofs.write((char*)&m_vPlaetze[i].m_vGeraete[z].m_uProzent,sizeof(unsigned char)); } }
ofs.close();
}
|
-- Demokratie ist die Diktatur der Mehrheit.
www.siedler25.org/ ( Siedler2 - Remake ) |