Reputation: 1523
I am trying to write a switch statement case that identifies all numbers from 0 to 9 in textual form. In gcc I believe it is possible to use the statement case '0'...'9':
Is there an equivalent expression that would work in Microsoft Visual Studio or will I have to write a separate case for each number?
Upvotes: 0
Views: 871
Reputation: 187
In gcc I believe it is possible to use the statement case '0'...'9'
Yes, but this is an extension of the GNU C Compiler, it is not C++ standard.
I think the best way to do that is to write something like that:
switch(c) {
case '0':
case '1':
case '2':
//...
case '9':
//Do something
break;
}
or, if you prefer:
switch(c) {
case '0': case '1': case '2': /*...*/ case '9':
//Do something
break;
}
(Note the spaces between :
and the following case
)
Upvotes: 1