avoid such code lik
if (isdigit(expression.at(i)) == true)
use more explicit code like
CHAR c = expression.at(i);
if( isdigit(c) )
to see better what is going on.
One very important point is that you use the ANSI version, but your string class may work with unicode. Read the details about atoi, _atoi_l, _wtoi, _wtoi_l
. My tip is that you better use _ttoi.
Learn to use the debugger, because I am sure that these exceptions are BUGS
in cour code.