Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > showpos problem

Reply
Thread Tools

showpos problem

 
 
fb
Guest
Posts: n/a
 
      12-01-2004
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.

 
Reply With Quote
 
 
 
 
Dietmar Kuehl
Guest
Posts: n/a
 
      12-01-2004
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';
--
<(E-Mail Removed)> <http://www.dietmar-kuehl.de/>
<http://www.contendix.com> - Software Development & Consulting

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments