bonjour je souhaite écrire dans un fichier plusieur informations préalablement lu dans une base de donnée ligne par ligne. Je met ces informations dans des variable et les met en entrées dans une fonction ecrire. Aussi j'ai fait une fonction ouvrir fichier en écriture et fermer fichier.Et rien ne s'écrit dans le fichier. Voici le code:
void C_Camping::Ecrire(AnsiString nom,AnsiString typ_veh,AnsiString empl,int ligne,int ligneMax)
{
//ifstream ifile(fichier);
//ofstream ofile(fichier, ios::ate);
if(ligne == 0)
{
ofile.clear(0);
ofile << "----------+---------------+-------------";
ofile <<"\n";
ofile << "|nom |type vehicule |emplacement |";
ofile <<"\n";
ofile << "----------+---------------+-------------";
ofile << "|" << setw(9) << nom << "|" << setw(15) << typ_veh << "|" << setw(12) << empl ;
ofile << "\n";
}
else
{
ofile << "|" << setw(9) << nom << "|" << setw(15) << typ_veh << "|" << setw(12) << empl ;
ofile << "\n";
ofile << "----------------------------------------";
ofile << "\n";
}
//if(ligne == (ligneMax-1))
// ofile.close();
}
//--------------------------------------------------------------------------
void C_Camping::OuvrirFicEcriture()
{
ifstream ifile(fichier);
ofstream ofile(fichier, ios::ate);
ofile.clear(0);
}
//--------------------------------------------------------------------------
void C_Camping::FermerFic()
{
ofile.close();
}
et voici le main :
camp.OuvrirFicEcriture();
for(i=0;i<nb2;i++)
{
bool lines = camp.bdd->Lireligne(i);
AnsiString nom = camp.bdd->afficherNomChamps(0);
AnsiString veh = camp.bdd->afficherNomChamps(1);
AnsiString empl = camp.bdd->afficherNomChamps(2);
StringGrid1->Cells[0][(i+1)] = nom;
StringGrid1->ColWidths[0] = nom.Length() * 15;
StringGrid1->Cells[1][(i+1)] = veh;
StringGrid1->ColWidths[1] = veh.Length() * 15;
StringGrid1->Cells[2][(i+1)] = empl;
StringGrid1->ColWidths[2] = empl.Length() * 15;
camp.Ecrire(nom.c_str(),empl.c_str(),veh.c_str(),i,nb2);
}
camp.FermerFic();
camp.bdd->libererEspaceMemoire();
Merci pour votre aide