values with fixed number of digits

This is a discussion on values with fixed number of digits within the C++ Programming forums, part of the General Programming Boards category; What c++ function can I use to print a value with a fixed number of digits? For instance 9 would ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    167

    values with fixed number of digits

    What c++ function can I use to print a value with a fixed number of digits? For instance 9 would be printed as 09.
    silk.odyssey

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    A combination of the setw stream manipulator and setfill would help here, to use these you must #include <iomanip>. Alternately, the output stream you are dealing (cerr, cout, etc.) has the necessary functions that you can call directly, i.e. cout.fill and cout.width.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    Thank you hk_mp5kpdw,

    setfll and setw does it for me
    silk.odyssey

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  2. decimal to number if digits in different bases
    By jorgejags in forum C Programming
    Replies: 21
    Last Post: 09-24-2008, 12:55 PM
  3. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  4. Count Number of Digits in and Integer
    By redneon in forum C++ Programming
    Replies: 2
    Last Post: 08-18-2003, 04:16 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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