if(c == '+' || '-' || '*' || '^' || '/' || '%')
analyzes on
if( (c == '+') || ('-'!=0) || ('*'!=0 || ('^'!=0) || ('/'!=0) || ('%'!=0))
It will always evaluate true because the '-' is indeed non-zero. Of course, this is a kind of flaw with a security type that char "degrades" to a boolean value and evaluates to true. (The correct safe solution would be to simply not compile your code unless you explicitly use it).
, c . . , :
C strchr:
if( strchr( "+-*^/%", c ) != NULL )
switch
switch (c )
{
case '+': case '-': case '*': case '^': case '/': case '%':
break;
default:
};
(overkill , ).
:: BitSet
"", , , , .
std::bitset<256> myCharSet;
myCharSet.set('+');
myCharSet.set('-');
myCharSet.set('*');
myCharSet.set('^');
myCharSet.set('/');
myCharSet.set('%');
if( myCharSet.test( static_cast<unsigned char>(c) ) )
{
}
else
{
}
, . static bool charset [256] = {false}; static bool init = false; if (! init) { charset ['+'] = true;// . init = true; }
if( charset[ static_cast<unsigned char>(c) ] )
{
}
else
{
}
, , , ( , 0 , , , ),
, .
(, ++ std::string, find std:: find), .