P
priyanka
Hi there,
I had a question. Is there any way of testing a string value in a
switch statement. I have about 50 string values that can be in a string
variable. I tried cheking them with the if else statements but it
looked pretty ugly and the string values to be tested is still
increasing. The switch statement seems to be a better choice then the
if else statement. But it seems that the switch statement accepts
integer values as the test condition. Can anybosy help me here or give
some idea ?
For eg,
switch(nameofInstitution){
case UofCanada: cout << " U of canada" << endl;
break;
case UofIndia: cout << " U of India" << endl;
break;
...................
.................
.....................
about 50 such cases
default: cout << " Sorry, this university is not listed"
<< endl;
die();
break;
}
Thank you,
Priya
I had a question. Is there any way of testing a string value in a
switch statement. I have about 50 string values that can be in a string
variable. I tried cheking them with the if else statements but it
looked pretty ugly and the string values to be tested is still
increasing. The switch statement seems to be a better choice then the
if else statement. But it seems that the switch statement accepts
integer values as the test condition. Can anybosy help me here or give
some idea ?
For eg,
switch(nameofInstitution){
case UofCanada: cout << " U of canada" << endl;
break;
case UofIndia: cout << " U of India" << endl;
break;
...................
.................
.....................
about 50 such cases
default: cout << " Sorry, this university is not listed"
<< endl;
die();
break;
}
Thank you,
Priya