1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| void Supprimer_etud()
{
string MON_FICHIER("D:/MON_FICHIER_APPL/FICHIER.txt");
ifstream flux(MON_FICHIER.c_str());//fichier contenant la ligne a supp
string MON_TAMPON("D:/MON_FICHIER_APPL/TAMPON.txt");
ofstream flux1(MON_TAMPON.c_str(),ios::app); //fichier tamporaire pour garder le contenu du fichier original excepte de la ligne a supprimer
int pos;
if(flux)
{
bool test;
string ligne,copie_ligne,chaine;
cout<<"donner le matricule : ";getline(cin,chaine);
getline(cin,chaine);
test=Rechercher_etud(chaine,copie_ligne);
if(test)
{
if(flux1)
{
while(getline(flux,ligne))
{
if(ligne==copie_ligne)
{
cout<<"ligne retrouver suppression en cour "<<endl;
continue;
}
else
{
flux1.seekp(0,ios::end);
int j=flux1.tellp();
if(j==0)
{
EN_TETE(MON_FICHIER);
flux1<<ligne<<endl;
}
else
{
flux1<<ligne<<endl;
}
}
}
}
else{cout<<"erreure douverture du fichier flux1 "<<endl;}
}
else{cout<<"le matricule n\'existe pas "<<endl;}
}
else
{
cout<<endl<<"ERREURE DOUVERTURE DU FICHIER"<<endl;
}
remove("FICHIER.txt");
rename("TAMPON.txt","FICHIER.txt");
} |
Partager