Like Tree1Likes
  • 1 Post By laserlight

How to display single digit int as four digit C++ Programming

This is a discussion on How to display single digit int as four digit C++ Programming within the C++ Programming forums, part of the General Programming Boards category; Hi all, How to display single digit int as four digit in C++.For example, i want to display the digit ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Location
    Coimbatore,INDIA
    Posts
    1

    Post How to display single digit int as four digit C++ Programming

    Hi all,

    How to display single digit int as four digit in C++.For example, i want to display the digit 12 as 0012 and 8 as 0008.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,445
    Set the width to 4 and the fill character to '0'. This can be easily done by #include <iomanip> with:
    Code:
    std::cout << std::setw(4) << std::setfill('0') << num << std::endl;
    By the way, we don't normally consider 12 to be a digit, unless you are expressing the number in base 13 or more.
    QuantumPete likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 04-17-2010, 11:31 AM
  2. Replies: 13
    Last Post: 11-13-2009, 07:47 AM
  3. Verifying single digit input
    By Syked4 in forum C Programming
    Replies: 8
    Last Post: 05-31-2005, 07:11 PM
  4. leading zero on single digit int
    By confuted in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2003, 04:48 PM
  5. ANSI value of a single digit
    By Iamien in forum C++ Programming
    Replies: 6
    Last Post: 05-24-2003, 05:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21