delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/08/31/23:52:14

Message-ID: <3B905BB5.3D9A5B60@erols.com>
Date: Fri, 31 Aug 2001 23:53:25 -0400
From: Chris Smith <herrsmitty AT erols DOT com>
X-Mailer: Mozilla 4.72 [en]C-CCK-MCD DT (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: <ios> and std::right?
References: <20010831220708 DOT 29894 DOT qmail AT web10004 DOT mail DOT yahoo DOT com> <1DXj7.190$tc5 DOT 58905722 AT news DOT netcarrier DOT net>
Reply-To: djgpp AT delorie DOT com

Remember, different things are sometimes defined or implimented a littlebit
differently depending on what compiler or OS you are using. That article
you pointed out may have been written with a different comiler in mind. The
following versions should work fine...

///////////////
//
// Program one
//
///////////////
#include <iostream>
int main() {
  std::cout.setf(std::ios::dec,
                 std::ios::basefield);
  std::cout.setf(std::ios::right,
                 std::ios::adjustfield);
  std::cout.width(10);
  std::cout << 42 << std::endl;
}

///////////////
//
// Program two
//
///////////////
#include <iostream>
#include <iomanip>
int main() {
  std::cout.setf(std::ios::hex,
                  std::ios::right);
  std::cout<<std::setw(10)
           <<42<<std::endl;
}


Brian Kennedy wrote:

> In message <20010831220708 DOT 29894 DOT qmail AT web10004 DOT mail DOT yahoo DOT com>, chris
> smith (c_smith_1 AT yahoo DOT com) wrote:
>
> :Use ios::right, not std::right.
>
> I didn't think ios::right was the same thing (?).
>
> For example, neither of these two programs (from
> http://www.cuj.com/experts/1902/austern.htm?topic=experts) will compile
> for me.  Shouldn't they work with DJGPP?
>
> ///////////////
> //
> // Program one
> //
> ///////////////
> #include <iostream>
> int main() {
>   std::cout.setf(std::ios_base::hex,
>                  std::ios_base::basefield);
>   std::cout.setf(std::ios::right,
>                  std::ios_base::adjustfield);
>   std::cout.width(10);
>   std::cout << 42 << std::endl;
> }
>
> ///////////////
> //
> // Program two
> //
> ///////////////
> #include <iostream>
> #include <iomanip>
> int main() {
>   std::cout << std::hex << std::right << std::setw(10);
>   std::cout << 42 << std::endl;
> }
>
> --------------------------------------------------------------
> Brian Kennedy
> brk AT eclipse DOT net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019