Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch Statement

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

How to use a switch statement for checking single characters? The following code didnt work. Will switch statement take only integers as condition??

AnsiString check;
switch(check.TOInt())
{
case 'a': /*something*/
break;
case 'b': /*something*/
break;
case 'c': /*something*/
break;
.
.
}
 
To my understanding, if you work with the type int then you should use: 'case 97:' (for 'a') etc. Or you can make your 'check' variable of type char: 'char check;', in this case you may keep the body of switch as is.

Alexandre.
 
Hi,
Thanx, that was helpful..But can I use an AnsiString as the condition check..


Rosilyn..
 
C++ does not allow the use of strings for conditions, only integers.
James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top