The function for accomplishing this was proposed by Roland on the following stack overflow thread.

sub_powers(string)

Arguments

string

Value

string suitable for C++