|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2007
Città: brianza
Messaggi: 717
|
[C++] switch con stringhe
mi serve fare delle condizioni multiple su una stringa, ma switch accetta solo int. quale potrebbe essere un'alternativa? non ho proprio voglia di fare una trentina di if
__________________
AMD Ryzen 9700X MSI RX 480 Gaming X 8G ASRock B850 Pro-A Windows 11 Pro RAM DDR5 16GBx2 TEAMGROUP T-Create Expert 6000 MHz CL30 SSD Crucial T500 4TB case Corsair Carbide 200R |
|
|
|
|
|
#2 | |
|
Bannato
Iscritto dal: Feb 2005
Città: Roma
Messaggi: 7029
|
Quote:
http://www.cplusplus.com/reference/stl/map/ un esempio: Codice:
typedef bool (*HANDLER)(); bool Handler1(); bool Handler2(); bool Handler3(); . . . map<const char*, HANDLER> Handlers; Handlers["stringa1"] = Handler1; Handlers["stringa2"] = Handler1; Handlers["stringa3"] = Handler1; ... Codice:
const char *String;
.
.
.
if (Handlers[String]())
{
// l'handler ha restituito true
}
else
{
// l'handler ha restituito false
}
|
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 08:12.




















