Bonjour, j'ai le code suivant mais j'ai un bug avec la ligne in >> ps.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
 
using namespace std;
typedef vector < string > numero;
 
 
 
class personne
{
public:
  string nom;
  numero num;
 
};
 
 
 
personne ps;
vector < personne > perso;
 
int main()
{
 
  ps.nom = "BERNARD";
  ps.num.push_back( "0164302859" );
  ps.num.push_back( "0673033015" );
  perso.push_back( ps );
 
  ofstream out( "fichier.txt", ios_base::app );
  for ( vector < personne >::const_iterator it = perso.begin(); it != perso.end(); it++ )
    out << it;
  out.close();
 
  perso.clear();
 
  ifstream in( "fichier.txt" );
  while ( in.good() )
  {
    in >> ps;
    if ( in.good() )
      perso.push_back( ps );
  }
  in.close();
 
 
  for ( vector < personne >::const_iterator it = perso.begin(); it != perso.end(); it++ )
  {
    cout << ps.nom << endl;
    for ( numero::const_iterator nu = ( * it ).num.begin(); nu != ( * it ).num.end(); nu++ )
    {
      cout << * nu << endl;
    }
  }
 
  return 0;
}