Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

why switch(a) converts char a into int decimal

the code needs to execute something depending on the .png filename passed as argv[1].

C++ switch does not accept strings, so all the files are named as cN.png where N is a digit between 0 and 9 and this digit is accessed with

string a=argv[1]; 
char aa=a[1];

On filename c6.png line

cout<<"aa="<<a[1]<<"; isdigit(aa)="<<isdigit(aa)<<endl;

returns aa=6; isdigit(aa)=1

yet switch(aa) seems to convert value 6 into its ASCII decimal code 54

I can get round it by replacing case 6 with case 54 in swich. Yet keen to know how to use swich in a more direct way. Perhaps aa should be of a different type?