I know the values of $a$ and $b$ and I want some other form of this equation to solve it using C++ programming language without overflow, because $a$ and $b$ can reach $100$.
I was thinking about logarithm but I could not complete the idea if we take the logarithm of the two sides:
$\log (a^b - b^a)$ = $\log x$
any idea?
Unless $a$ and $b$ are very close, one of these will be much larger than the other. In that case if either one overflows the difference will, too, so you might as well just do the straightforward computation. Contrast $$10^{12}=1,000,000,000,000\\12^{10}=61,917,364,224$$ Taking the difference doesn't reduce $10^{12}$ much at all. If $a,b$ are integers just test for equality. If they are equal return $0$, otherwise compute it as written and let it overflow.