title: Counting digits using while loop
body: <p>I was recently making a program which needed to check the number of digits in a number inputted by the user. As a result I made the following code:</p>
  
  <pre><code>int x;    
  cout &lt;&lt; "Enter a number: ";
  cin &gt;&gt; x;
  x /= 10;
  while(x &gt; 0)
  {
    count++;
    x = x/10;
  }
  </code></pre>
  
  <p>From what I can tell (even with my limited experience) is that it seems crude and rather unelegant.</p>
  
  <p>Does anyone have an idea on how to improve this code (while not using an inbuilt c++ function)?</p>