473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I used
#include <iostream.h>
int m;
cout << "Hexadecima l == 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 9020
"Ensoul Chee" <mp**@sohu.co m> 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 << "Hexadecima l == 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 << "Hexadecima l == 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 << "Hexadecima l == 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 << "Hexadecima l == 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 << "Hexadecima l == 0x" << std::hex << m << '\n';
}

HTH,
Sumit.

Jul 19 '05 #5
Ensoul Chee wrote:
I used
#include <iostream.h>
int m;
cout << "Hexadecima l == 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************ *********@never box.com> writes:
Ensoul Chee wrote:
I used
#include <iostream.h>
int m;
cout << "Hexadecima l == 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
17714
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(), xml_set_element_handler() etc. functions. I have difficulties with special characters in the data. I found information on "<!]>", UTF-8, XML DOM,
2
8855
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 used until reset". For some reason, I interpreted this to mean that "<< hex" manipulator would cause the base to be set for only the current statement, while the cout.setf(ios_base::hex) statement would cause the base to be set for multiple...
4
8027
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; //Logging in $submit_url =
7
2652
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 if I use the web test interface. It also works fine if I call it from an ASP.NET page that has a text box where the XML is pasted and then passed on. However, I get an exception if I use an <input type="file"> control on the ASP page that allows...
7
19249
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: var location = new Array() <cfloop query="loc"> location.name = '#loc.name#' location.address1 = '#loc.address1#'
5
12291
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. On Beta1, I am able to execute a particular page with no problem, that page opens up in the comes up just fine. On Win2kdev1, when I go to execute the same page, it opens a file download dialog and asks me whether I want to open or save the...
9
9122
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 ! Ex. a = 0x80000004 if ( using printf("%x",a) ) then I got "80000004" on screen
2
2797
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 program sorts out every doublet and the hexadecimal unicode code is extracted, but I dont know a way to find the xml or sgml-entity equivalent to the unicode code. Anyone who could give me a pointer? Best regards
19
2843
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have <a href="javascript:somefunction()"what ... ? ----------------------------------------------------------------------- Whatever the rest of your question, this is generally a very bad use of the javascript pseudo protocol. It was designed so that a function could return a new page. For example: `` javascript:"<p>Hello</p>" ''. Using it simply to...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7320
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.