473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
Jul 19 '05 #1
2 8277
In article <VP******************@twister.austin.rr.com>,
Christopher <cp***@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 <jt*******@presby.edu> Presbyterian College
Dept. of Physics and Computer Science Clinton, South Carolina USA
Jul 19 '05 #2
In article <VP******************@twister.austin.rr.com>,
cp***@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.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Vaxius | last post by:
After trying to compile the following code, gcc gives me error: 'setwidth' was not declared in this scope I'm not sure why it would do this, since iomanip is included. Am I missing something?...
4
by: alternativa | last post by:
Hi, I'd like to obtain an output looking as follows: name number phone address Caroline 233 34234 White St. 12 Anna 929043 093284 Brown St. 325...
6
by: Martin Eisenberg | last post by:
What do I need to make this work? #include <iostream> #include <fstream> using namespace std; struct LoggedCout { ofstream file; LoggedCout(const char* name) : file(name, ios::app) {}
2
by: rupert | last post by:
i've got the following code: #include <iostream> #include <string> #include <vector> #include <iomanip> using namespace std; int main(double argc, char* argv) { double r = 0.01;
3
by: PengYu.UT | last post by:
Hi, I setprecision to be 100 for both cases. I'm wondering why the number of digits are different. Also, for a double number, I think any digits that are longer than 15 (or 16) are not...
2
by: brekehan | last post by:
I can't seem to get the alignment to switch back and forth combined with a set width. I tryed a search on this group and alot of googling, but still can't deduce the problem. #include <iostream>...
2
by: khosrow | last post by:
i'm having a problem with iomanip. i use cout<< fixed<< setprecision(5); and it just does not recognize "fixed" i use cout<< setprecision(5)<< showpoint<< x<< endl; this time not recognizing...
1
by: [rob desbois] | last post by:
Hi all, I've just discovered that when outputting a string in combination with the I/O manipulator setw(n), it doesn't affect the string. Instead the string's c_str() method must be called for...
6
by: Bernd Gaertner | last post by:
Dear experts, according to the standard, manipulators like noskipws are declared in the header ios (). But when I look at code that is around, I usually see #include<iomanipbeing used. What is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.