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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
| #include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
struct Identite
{
string nom;
string prenom;
int age;
char statut;
};
struct Date
{
int d;
int m;
int y;
};
struct Client
{
Date date;
Identite id;
int montantEmprunt;
int tauxInteret;
int duree;
int montantInteret;
};
ostream& operator << (ostream& flux, Date & D)
{
flux << D.d << " " << D.m << " " << D.y;
return flux;
}
istream& operator >> (istream& flux, Date & D)
{
flux >> D.d >> D.m >> D.y;
return flux;
}
ostream& operator << (ostream& flux, Identite & I)
{
flux << I.nom << " " << I.prenom << " " << I.age << " " << I.statut;
return flux;
}
istream& operator >> (istream& flux, Identite & I)
{
flux >> I.nom >> I.prenom >> I.age >> I.statut;
return flux;
}
ostream& operator << (ostream& flux, Client & C)
{
flux << C.id << " " << C.date << " " << C.montantEmprunt << " ";
flux << C.tauxInteret << " " << C.duree << " " << C.montantInteret;
return flux;
}
istream& operator >> (istream& flux, Client & C)
{
flux >> C.id >> C.date >> C.montantEmprunt >> C.tauxInteret >> C.duree >> C.montantInteret;
return flux;
}
vector<Client> LireFichier(string filename)
{
ifstream file(filename.c_str());
Client client;
vector<Client> tabClient;
if (file)
while (file >> client)
tabClient.push_back(client);
return tabClient;
}
int main ()
{
vector<Client> listeClients = LireFichier("fichier.txt");
cout << "Nombre de clients : " << listeClients.size() << endl;
for (int i = 0; i < listeClients.size(); i++)
cout << listeClients[i] << endl;
return EXIT_SUCCESS;
} |
Partager