| 12
 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
 
 |  
void EnC()
{ string z( "NL=000120 NC=044 W=8 P=003" ) ; 
  size_t  nl, nc, w , p ;
 
  cout << z << endl ;
 
  int res  = sscanf( z.c_str() , "NL=%u NC=%u W=%u P=%u", &nl, &nc, &w , &p ) ;
  if( res == 4 )
  cout << "NL= " << nl << " NC= " << nc << " W= " << w << " P= " << p << endl;
  else
  cout << "Pas bon" << endl ; 
}
 
 
void EnCpp()
{ string z( "NL=000120 NC=044 W=8 P=003" ) ; 
  size_t  nl, nc, p, w ;
 
  cout << z << endl ;
 
  istringstream  is( z ) ;
  string mot ;
 
 
  while( getline( is, mot, ' ' ) )
  {  
     string tp ;
     istringstream iss( mot ) ;
     getline( iss, tp, '=' ) ;
     if( tp == "NL" ) 
     { getline( iss, tp, '=' ) ;
       istringstream ( tp ) >> nl ;
     }
     if( tp == "NC" ) 
     { getline( iss, tp, '=' ) ;
       istringstream ( tp ) >> nc ;
     }
     if( tp == "W" ) 
     { getline( iss, tp, '=' ) ;
       istringstream ( tp ) >> w ;
     }
     if( tp == "P" ) 
     { getline( iss, tp, '=' ) ;
       istringstream ( tp ) >> p ;
     }
 
  }
 
  cout << "NL= " << nl << " NC= " << nc << " W= " << w << " P= " << p << endl;
 
} | 
Partager