just use &, like:
int i=0;
cout << &i;
if you have a pointer:
int i=new int();
cout << i << endl;
works great.
Thanks,
_|_|_|_|_| _| _|_|_|_|
_| _|_|_| _| _|_|_|
_| _| _| _|_|_| _|
_| _| _| _| _|
_| _| _| _|_|_|_| _|_|_|
Visit TDS for quality software and website production
http://tysdomain.com
msn: [EMAIL PROTECTED]
aim: st8amnd2005
skype: st8amnd127
----- Original Message -----
From: ~Rick
To: c-prog
Sent: Thursday, September 11, 2008 3:31 PM
Subject: [c-prog] printing the address of a variable using cout
Hi all,
I am trying to print the address of a variable, not the contents of it.
Using printf, I would say:
printf("Allocated %ld bytes at %p\n", bsize+1, fbuf);
but I want to use the C++ features using cout/cerr. I've tried the
following but get garbage:
long int bsize = 1023;
char *fbuf;
fbuf = new char[bsize+1];
if (fbuf)
{
cerr.flags(ios::dec);
cerr << "Allocated " << (bsize+1) << " bytes at ";
cerr.flags(ios::hex);
cerr << fbuf << endl;
delete [] fbuf;
}
I have searched but can only find ios flags for dec, hex, oct but not
for ptr. What is the "secret" here?
~Rick
__________ NOD32 3435 (20080911) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
[Non-text portions of this message have been removed]