I have a problem with overkilling the simple things I guess... So I won't kill all of your fun, I'll leave the leading zero issue up to you to solve (if there is even a potential for it to be a problem)
#include <iostream>
#include <sstream>
int CountDigits (int source);
std::string itos (int num);
int main (void)
{
int x = 0;
int y = 12345;
x = CountDigits(y);
std::cout << "There are " << x << " digits in " << y << std::endl;
std::cin >> y;
return 0;
}
int CountDigits (int source)
{
int count = 0;
std::string z = itos(source);
return z.length();
}
std::string itos (int num)
{
std::ostringstream myStream;
myStream << num << std::flush;
return (myStream.str());
}