iomanip



 DEVELOP > c-Plus-Plus > iomanip

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Christopher"
Date: 09 Nov 2003 02:54:13 PM
Object: iomanip
Can someone give me an example of how to use the hex manipulator defined in
<iomanip>. I am reading the doc but it doesnt give me the syntax, or at
least I don't understand it.
Thanx,
Christopher
.

User: "Jon Bell"

Title: Re: iomanip 09 Nov 2003 03:30:06 PM
In article <VPxrb.23106$PH6.3642@twister.austin.rr.com>,
Christopher <cpisz@austin.rr.com> wrote:

Can someone give me an example of how to use the hex manipulator defined in
<iomanip>.

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int num = 1234;
cout << "Decimal = " << num
<< ", Hexadecimal = " << hex << num << endl;
return 0;
}
--
Jon Bell <jtbellap8@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
.

User: "Jerry Coffin"

Title: Re: iomanip 09 Nov 2003 04:25:43 PM
In article <VPxrb.23106$PH6.3642@twister.austin.rr.com>,
cpisz@austin.rr.com says...

Can someone give me an example of how to use the hex manipulator defined in
<iomanip>. I am reading the doc but it doesnt give me the syntax, or at
least I don't understand it.

#include <iostream>
#include <iomanip>
int main() {
std::cout << std::hex << 12345;
return 0;
}
Note that there are two entirely different things named "hex" -- the one
I used above is a manipulator. The other (std::ios::hex) is a constant
value that will set a base to hexadecimal when it's passed to
setiosflags -- if you accidentally print it out, you'll get some value
(normally a power of two) preceding your own value, which will still be
printed in decimal. E.g. the output from the program above should be
"3039", which is 12345 converted to hexadecimal. OTOH, code like this:
std::cout << std::ios::hex << 12345;
will typically produce output something like "1612345" or "204812345".
--
Later,
Jerry.
The universe is a figment of its own imagination.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER