showpos problem

Discussion in 'C++' started by fb, Dec 1, 2004.

  1. fb

    fb Guest

    Hi everyone...

    I have a small problem with showpos placing a '+' in the wrong spot.

    What I have is:
    0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
    ....
    ....
    I want to place a '+' in front of all these as so:
    +0000 +0000 +0000 +0000 +0000 etc...
    ....
    ....

    The problem with the code below is that the '+' sign is placed in a
    wierd spot. Something like: 00+0

    (notes: 'Accumulator' is an int that holds a value from -9999 to 9999)

    cout << "accumulator: " << showpos << setw(4) << setfill('0') <<
    Accumulator << endl;

    Thanks.
     
    fb, Dec 1, 2004
    #1
    1. Advertising

  2. fb wrote:
    > The problem with the code below is that the '+' sign is placed in a
    > wierd spot. Something like: 00+0
    >
    > (notes: 'Accumulator' is an int that holds a value from -9999 to

    9999)
    >
    > cout << "accumulator: " << showpos << setw(4) << setfill('0') <<
    > Accumulator << endl;


    Why do you think it is placed in a weird spot? The fill character
    is not part of the value but intended to be something like e.g.
    a space. You can, however, still arrange this formatting by using
    "internal" for the adjustment which insert the fill character at
    some appropriate internal point:

    | std::cout << std::showpos << std::setw(4) << std::setfill('0')
    | << std::internal << 0 << '\n';
    --
    <mailto:> <http://www.dietmar-kuehl.de/>
    <http://www.contendix.com> - Software Development & Consulting
     
    Dietmar Kuehl, Dec 1, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas Suurkuusk
    Replies:
    0
    Views:
    4,032
    Andreas Suurkuusk
    Jul 27, 2003
  2. Ted Miller
    Replies:
    0
    Views:
    5,222
    Ted Miller
    Sep 13, 2003
  3. Merek
    Replies:
    0
    Views:
    2,001
    Merek
    Dec 3, 2003
  4. Scott Meddows
    Replies:
    1
    Views:
    421
    John Saunders
    Jun 8, 2004
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    581
    Bullschmidt
    May 11, 2004
Loading...

Share This Page