I want to split an integer of type unsigned long long to its digits.
Any comments and suggestions are always welcome.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<unsigned short> IntegerDigits(unsigned long long input)
{
vector<unsigned short> output;
const unsigned short n = log10(ULLONG_MAX);
unsigned long long divisor = pow(10, n);
bool leadingZero = true;
for (int i = 0; i < n + 1; i++)
{
unsigned short digit = input / divisor % 10;
if (!leadingZero || digit != 0)
{
output.push_back(digit);
leadingZero = false;
}
divisor /= 10;
}
return output;
}
void main()
{
vector<unsigned short> output = IntegerDigits(ULLONG_MAX);
cout << ULLONG_MAX << ": [";
for (auto y : output)
cout << y << ", ";
cout << "\b\b]";
cout << ""<<endl;
}