473,386 Members | 1,610 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,386 software developers and data experts.

compile error with "cout << "Hexadecimal == 0x" << hex << m << endl;"

I used
#include <iostream.h>
int m;
cout << "Hexadecimal == 0x" << hex << m << endl;

to print value of m in hexadecimal mode.

But I got the compile error like this

couttest.cpp:20 `hex' undeclared (first use this function)

What's wrong with the code?

OS: Redhat 9
Compiler: gcc 3.2.2
Jul 19 '05 #1
7 8993
"Ensoul Chee" <mp**@sohu.com> wrote...
I used
#include <iostream.h>
Stop using this non-standard header. Its time have long been over.
Start using <iostream>. Read about 'std' namespace as well.
int m;
cout << "Hexadecimal == 0x" << hex << m << endl;
'm' is used here without being initialised. That is a very bad
mistake on some systems.

to print value of m in hexadecimal mode.
'm' has indeterminate value. You can't really expect to see anything
sensible.

But I got the compile error like this

couttest.cpp:20 `hex' undeclared (first use this function)

What's wrong with the code?
Use of non-standard header. The code is a non-compilable fragment.
Perhaps you should read FAQ 5.8.
OS: Redhat 9
Compiler: gcc 3.2.2


#include <iostream>
int main()
{
int m = 42;
std::cout << "Hex of " << m << " is " \
<< std::hex << m << std::endl;
}

Victor
Jul 19 '05 #2
mp**@sohu.com (Ensoul Chee) writes:
I used
#include <iostream.h>
This header is deprecated, use #include <iostream>
int m;
cout << "Hexadecimal == 0x" << hex << m << endl;

to print value of m in hexadecimal mode.

But I got the compile error like this

couttest.cpp:20 `hex' undeclared (first use this function)

What's wrong with the code?


Everything from the standard library lives in the std:: namespace,
so you have to use the prefix std:: or an using declaration/directive.
The following example should work:

#include <iostream>

int main() {
int m = 13;
std::cout << "Hexadecimal == 0x" << std::hex << m << std::endl;
return 0;
}

HTH & kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frank DOT schmitt AT 4sc DOT com
Jul 19 '05 #3

"Frank Schmitt" <fr***********@4sc.com> wrote in message news:4c************@scxw21.4sc...
mp**@sohu.com (Ensoul Chee) writes:
I used
#include <iostream.h>


This header is deprecated, use #include <iostream>


It's not deprecated, it's just plain wrong. iostream.h is not
part of the standard language.
Jul 19 '05 #4
Ensoul Chee wrote:
I used
#include <iostream.h>
int m;
cout << "Hexadecimal == 0x" << hex << m << endl;

to print value of m in hexadecimal mode.

But I got the compile error like this

couttest.cpp:20 `hex' undeclared (first use this function)

What's wrong with the code?

The problem is that hex resides in the std namespace. So you will need to
try something like:
#include <iostream>

int main()
{
int m = 255;
std::cout << "Hexadecimal == 0x" << std::hex << m << '\n';
}

HTH,
Sumit.

Jul 19 '05 #5
Ensoul Chee wrote:
I used
#include <iostream.h>
int m;
cout << "Hexadecimal == 0x" << hex << m << endl;

to print value of m in hexadecimal mode.

But I got the compile error like this

couttest.cpp:20 `hex' undeclared (first use this function)

What's wrong with the code?

OS: Redhat 9
Compiler: gcc 3.2.2


In addition to the other replies, std::hex is technically presented in
<ios>. <ios> is probably #included in <iostream>, but I don't know if
this is required.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #6
Kevin Goodsell <us*********************@neverbox.com> writes:
Ensoul Chee wrote:
I used
#include <iostream.h>
int m;
cout << "Hexadecimal == 0x" << hex << m << endl;
to print value of m in hexadecimal mode. But I got the compile error
like this
couttest.cpp:20 `hex' undeclared (first use this function)
What's wrong with the code?
OS: Redhat 9
Compiler: gcc 3.2.2


In addition to the other replies, std::hex is technically presented in
<ios>. <ios> is probably #included in <iostream>, but I don't know if
this is required.


It's not. <iostream> requires several things from <ios>, but AFAIK,
it doesn't require the manipulators. So you can't rely on them
being provided by <iostream> . Really, all <iostream> provides is
cin, clog, cerr, cout, and their wide character equivalents. Lots
of other stuff comes long just becuase those objects have complex
types, which require many things, but not the manipulators.
Jul 19 '05 #7
Thanks for your reply.

I think I need to find a good book to learn c++.

That code is copy from a book about GNU C++ for linux program.
Jul 19 '05 #8

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

Similar topics

6
by: John van Terheijden | last post by:
Hi. I'm trying to develop a program that uses XML files store data. I'm using Windows XP, Apache 1.3.29 and PHP 4.3.4. Right now the XML file is read using the xml_parser_create(),...
2
by: Generic Usenet Account | last post by:
What exactly is the difference between the hex manipulator and the following statement: cout.setf(ios_base::hex)? According to Stroustrup, Third Edition, Section 21.4.4, "once set, a base is...
4
by: futureofphp | last post by:
I need to access a website, Fetch the data, and then logout. Please tell me where I am wrong. I dont think its logging out properly. <? include "Snoopy.class.php"; $snoopy = new Snoopy; ...
7
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine...
7
by: James Johnson | last post by:
Are there structs in JavaScript? If not, what's the closest thing, or do I just use parallel arrays? I'm populating a JavaScript array from ColdFusion query, but I don't think I can do this: ...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
9
by: liaoo | last post by:
Dear all, I have a question about using cout<<... In standard C, I can use printf("%x",...) to print "hex" number. But in Watcom C++, when using cout<<, I got the "decimal" representation ! ...
2
by: Frantic | last post by:
I'm working on a list of japaneese entities that contain the entity, the unicode hexadecimal code and the xml/sgml entity used for that entity. A unicode document is read into the program, then the...
19
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have <a href="javascript:somefunction()"what ... ?...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.