Results 1 to 2 of 2

Thread: silly question

  1. #1

    Thread Starter
    Registered User jkw119's Avatar
    Join Date
    Oct 2001
    Location
    Pittsburgh
    Posts
    256

    silly question

    I have kind of a silly question...

    I am trying to display an Integer as 0001, istead of 1. And when I increment it, I need it to be 0002, 0003, ....0124, etc. Does anyone know how I can do so?

    Thanks,

    Jeff

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    Using C++:
    Code:
    #include <iostream>
    #include <iomanip>
    
    int main()
    {
        int i = 1;
        std::cout << std::setw(4) << std::setfill('0') << i; // prints "0001"
        return 0;
    }
    Using C:
    Code:
    #include <stdio.h>
    
    int main()
    {
        int i = 1;
        printf("%04i",i); // 0001
        return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width