Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > another strange output?

Reply
Thread Tools

another strange output?

 
 
RB
Guest
Posts: n/a
 
      07-30-2010
I just recently was educated that I should be using #include <iostream>
instead of using #include <iostream.h> as I had been doing.
However, even though the education cured one strange output issue, now
with the "correct" include spec I cannot get it to show the radix base like
it used to using the "incorrect" include spec.
Very much appreciate info as to what I am still missing. Code below
==============================================
#include <windows.h>
#include <iostream> // correct include spec
using namespace std;

// #include <iostream.h> // incorrect include spec

struct _Whatever
{
DWORD dw1;
DWORD dw2;
};

int main( )
{
_Whatever* pA = new _Whatever;
pA->dw1 = 0xAAAA;
pA->dw2 = 0xBBBB;

cout.flags ( ios::hex | ios::showbase ); // want to show radix

cout << "The allocated heap address that pA and/or pA->dw1 points is " << pA
<< "\nThe allocated address that pA->dw2 points is " << &pA->dw2
<< "\nThe address of the local pA pointer (on stack) " << &pA
<< endl;
delete pA;
return 0;
}

/*------------- program output if using correct include of
#include <iostream>
using namespace std;

The allocated heap address that pA and/or pA->dw1 points is 00331C48
The allocated address that pA->dw2 points is 00331C4C
The address of the local pA pointer (on stack) 0012FF7C

// Does not showbase ???
--------------*/

/*------------- program output if using incorrect include of
#include <iostream.h>

The allocated heap address that pA and/or pA->dw1 points is 0x003308C8
The allocated address that pA->dw2 points is 0x003308CC
The address of the local pA pointer (on stack) 0x0012FF7C

// Does showbase but include is incorrect ???
-------------*/
 
Reply With Quote
 
 
 
 
Francesco S. Carta
Guest
Posts: n/a
 
      07-30-2010
RB <NoMail@NoSpam>, on 30/07/2010 08:43:13, wrote:

> I just recently was educated that I should be using #include <iostream>
> instead of using #include <iostream.h> as I had been doing.
> However, even though the education cured one strange output issue, now
> with the "correct" include spec I cannot get it to show the radix base like
> it used to using the "incorrect" include spec.
> Very much appreciate info as to what I am still missing. Code below
> ==============================================
> #include <windows.h>
> #include <iostream> // correct include spec
> using namespace std;
>
> // #include <iostream.h> // incorrect include spec
>
> struct _Whatever { DWORD dw1; DWORD dw2; };
> int main( ) {
> _Whatever* pA = new _Whatever;
> pA->dw1 = 0xAAAA;
> pA->dw2 = 0xBBBB;
>
> cout.flags ( ios::hex | ios::showbase ); // want to show radix
>
> cout << "The allocated heap address that pA and/or pA->dw1 points is "
> << pA
> << "\nThe allocated address that pA->dw2 points is " << &pA->dw2
> << "\nThe address of the local pA pointer (on stack) " << &pA
> << endl;
> delete pA; return 0; }
>
> /*------------- program output if using correct include of #include
> <iostream>
> using namespace std;
>
> The allocated heap address that pA and/or pA->dw1 points is 00331C48
> The allocated address that pA->dw2 points is 00331C4C
> The address of the local pA pointer (on stack) 0012FF7C
>
> // Does not showbase ???
> --------------*/
>
> /*------------- program output if using incorrect include of #include
> <iostream.h>
>
> The allocated heap address that pA and/or pA->dw1 points is 0x003308C8
> The allocated address that pA->dw2 points is 0x003308CC
> The address of the local pA pointer (on stack) 0x0012FF7C
>
> // Does showbase but include is incorrect ???
> -------------*/


Works for me - MinGW 4.4.0 here - the leading 0x base gets correctly
printed by compiling and running the code with the _correct_ header
<iostream>.

I think you'll find tons of other mis-working features with that old
compiler you're using - VC 6.0 if I recall correctly... didn't you say
you have VS2005 under hands?

--
FSC - http://userscripts.org/scripts/show/59948
http://fscode.altervista.org - http://sardinias.com
 
Reply With Quote
 
 
 
 
Ron AF Greve
Guest
Posts: n/a
 
      07-30-2010
Hi,

#include <iomanip>

"RB" <NoMail@NoSpam> wrote in message news:(E-Mail Removed)...
| I just recently was educated that I should be using #include <iostream>
| instead of using #include <iostream.h> as I had been doing.
| However, even though the education cured one strange output issue, now
| with the "correct" include spec I cannot get it to show the radix base
like
| it used to using the "incorrect" include spec.
| Very much appreciate info as to what I am still missing. Code below
| ==============================================
| #include <windows.h>
| #include <iostream> // correct include spec
| using namespace std;
|
| // #include <iostream.h> // incorrect include spec
|
| struct _Whatever
| {
| DWORD dw1;
| DWORD dw2;
| };
|
| int main( )
| {
| _Whatever* pA = new _Whatever;
| pA->dw1 = 0xAAAA;
| pA->dw2 = 0xBBBB;
|
| cout.flags ( ios::hex | ios::showbase ); // want to show radix
|
| cout << "The allocated heap address that pA and/or pA->dw1 points is "
<< pA
| << "\nThe allocated address that pA->dw2 points is
" << &pA->dw2
| << "\nThe address of the local pA pointer (on stack)
" << &pA
| << endl;
| delete pA;
| return 0;
| }
|
| /*------------- program output if using correct include of
| #include <iostream>
| using namespace std;
|
| The allocated heap address that pA and/or pA->dw1 points is 00331C48
| The allocated address that pA->dw2 points is
00331C4C
| The address of the local pA pointer (on stack)
0012FF7C
|
| // Does not showbase ???
| --------------*/
|
| /*------------- program output if using incorrect include of
| #include <iostream.h>
|
| The allocated heap address that pA and/or pA->dw1 points is 0x003308C8
| The allocated address that pA->dw2 points is
0x003308CC
| The address of the local pA pointer (on stack)
0x0012FF7C
|
| // Does showbase but include is incorrect ???
| -------------*/

--
Regards, Ron AF Greve

http://informationsuperhighway.eu



 
Reply With Quote
 
James Lothian
Guest
Posts: n/a
 
      07-30-2010
RB wrote:
> I just recently was educated that I should be using #include <iostream>
> instead of using #include <iostream.h> as I had been doing.
> However, even though the education cured one strange output issue, now
> with the "correct" include spec I cannot get it to show the radix base like
> it used to using the "incorrect" include spec.
> Very much appreciate info as to what I am still missing. Code below


As far as I can tell, the problem is that you're outputting pointers, not
integers. As far as I can tell (standard 27.4.2.1.4), ios::hex and
ios::showbase control output of integers only.

James

 
Reply With Quote
 
Francesco S. Carta
Guest
Posts: n/a
 
      07-30-2010
Ron AF Greve <me@localhost>, on 30/07/2010 15:37:09, wrote:

<edited, talking about including ios::hex and ios::showbase>

> Hi,
>
> #include<iomanip>


Those manipulators are defined in <ios> which gets included by
<iostream> via <istream> (at least on my implementation, but I think it
is the correct behaviour as
http://www.cppreference.com/wiki/io/io_flags
reports), hence, there is no real need for <iomanip>.

Although that could eventually solve the OP problem, this is not really
requested.

The issue at hand is that the OP uses an old compiler which messes up
otherwise perfectly correct code.

Besides, please avoid top posting.

--
FSC - http://userscripts.org/scripts/show/59948
http://fscode.altervista.org - http://sardinias.com
 
Reply With Quote
 
RB
Guest
Posts: n/a
 
      07-30-2010
> Works for me - MinGW 4.4.0 here - the leading 0x base gets correctly
> printed by compiling and running the code with the _correct_ header
> <iostream>.
>
> I think you'll find tons of other mis-working features with that old
> compiler you're using - VC 6.0 if I recall correctly... didn't you say
> you have VS2005 under hands?


Yes, that must be it, although I will have to reinstall it on my laptop
since the machine I had 2005 on had a drive failure.
Thanks for the reply
 
Reply With Quote
 
RB
Guest
Posts: n/a
 
      07-30-2010

> #include <iomanip>


I tried that but it did not work. I suspect it is my old compiler.
I need to reinstall 2005 on my laptop.
Thanks for the reply though.
 
Reply With Quote
 
RB
Guest
Posts: n/a
 
      07-30-2010
> As far as I can tell, the problem is that you're outputting pointers, not
> integers. As far as I can tell (standard 27.4.2.1.4), ios::hex and
> ios::showbase control output of integers only.


I think it is my old compiler. However in the past I have noted that
pointers will output with their "own base added and lower case hex"
regardless of how I have my cout.flags set. But I have never seen
them ignore the base printout completely.
In any case thanks for the reply.
 
Reply With Quote
 
James Lothian
Guest
Posts: n/a
 
      07-30-2010
RB wrote:
>> As far as I can tell, the problem is that you're outputting pointers, not
>> integers. As far as I can tell (standard 27.4.2.1.4), ios::hex and
>> ios::showbase control output of integers only.

>
> I think it is my old compiler. However in the past I have noted that
> pointers will output with their "own base added and lower case hex"
> regardless of how I have my cout.flags set. But I have never seen
> them ignore the base printout completely.
> In any case thanks for the reply.

I've tried your example on vs2008, both with and without the cout.flags()
call, and got exactly the same results you did. So, I wouldn't rely on
a compiler update to fix the problem. Your best bet is probably to
convert the pointers to integers before outputting them.

James

 
Reply With Quote
 
Francesco S. Carta
Guest
Posts: n/a
 
      07-30-2010
James Lothian <(E-Mail Removed)>, on 30/07/2010
15:27:11, wrote:

> RB wrote:
>>> As far as I can tell, the problem is that you're outputting pointers,
>>> not
>>> integers. As far as I can tell (standard 27.4.2.1.4), ios::hex and
>>> ios::showbase control output of integers only.

>>
>> I think it is my old compiler. However in the past I have noted that
>> pointers will output with their "own base added and lower case hex"
>> regardless of how I have my cout.flags set. But I have never seen
>> them ignore the base printout completely.
>> In any case thanks for the reply.

> I've tried your example on vs2008, both with and without the cout.flags()
> call, and got exactly the same results you did. So, I wouldn't rely on
> a compiler update to fix the problem. Your best bet is probably to
> convert the pointers to integers before outputting them.


For what is worth, here with MinGW 4.4.0 it's the other way around: the
OP code outputs the addresses in hex notation and with the leading 0x
base even without the cout.flags() instruction.

I wonder what is the default behaviour for outputting addresses on a
"clean" cout stream. It might well be that the standard does not specify it.

--
FSC - http://userscripts.org/scripts/show/59948
http://fscode.altervista.org - http://sardinias.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AVG Email Scanner activating at strange times with strange IP addresses dennispublic@hotmail.com Computer Support 1 08-26-2006 04:27 AM
strange file upload behaviour (404 with one pdf but not with another) mikecom@gmx.net ASP .Net 3 06-27-2006 10:15 AM
Another strange file--what is this?? MZB Computer Support 1 11-19-2005 07:08 PM
Another strange compile error with visual studio c++ 6.0 Gunnar G C++ 5 10-21-2005 12:49 AM
Question About Strange 'C' Code Syntax ( Well strange to me anyway ) Harvey Twyman C Programming 8 10-25-2003 05:54 AM



Advertisments