CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Location
    Bangalore
    Posts
    78

    Format Specifier!

    Hi All,

    Is there is any format specifier, which can be used to print the sign of the number?

    For example,

    If I enter 10, it should print as +10.
    If I enter -2, it should print as -2.

    With Thanks and Regards,
    A.Ilamparithi

  2. #2
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Format Specifier!

    With printf, there is one.
    Try this one:
    Code:
    printf("the integer is : %+i",10);

  3. #3
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Format Specifier!

    With iostream:
    Code:
    std::cout << std::showpos << 42 << std::noshowpos;
    There is a flag showpos in the format flags of ios, set by the manipulator std::showpos, and removed by the manipulator std::noshowpos.

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

Featured