Armstrong number

I wrote the following code but it fails test cases 0 and 1. Please explain the mistake in my code.

#include < iostream >
#include < cmath >
using namespace std;

int main()
{
long long int n;
cin>>n;
int num = n;
int ans = 0;
int digit;

while(n>0)
{
	digit = n%10;
	ans = ans + pow(digit,3);
	n = n/10;
}
if(ans==num)
{
	cout<<"true";
}
else
{
	cout<<"false";
}
return 0;

}

Hey @shreyasdaga
Replace this by pow(digit,int(log10(k)+1));

Why?
Re read when its armstrong number