J
Jacek Dziedzic
Hello!
I have a piece of code that needs to display a formatted
table of pointers using streams, with the pointers represented
as hex values. It looks more or less like this:
#include <iostream>
#include <iomanip>
using namespace std;
// ptr[] is an array of pointers
int main() {
for(unsigned int i=0;i<some_size;++i) {
cout << hex << setprecision(16) << setw(20)
<< (void*)ptr << '\n';
}
}
What annoys me is that if ptr is NULL, then it does
get output as ' 0' instead of
'0x0000000000000000' as I'd like it to print.
Can anyone suggest a solution to this, other than
checking for NULL manually? Casting to int is not an
option since pointers are 8-byte and ints are 4-byte
on my system.
thanks in advance,
- J.
I have a piece of code that needs to display a formatted
table of pointers using streams, with the pointers represented
as hex values. It looks more or less like this:
#include <iostream>
#include <iomanip>
using namespace std;
// ptr[] is an array of pointers
int main() {
for(unsigned int i=0;i<some_size;++i) {
cout << hex << setprecision(16) << setw(20)
<< (void*)ptr << '\n';
}
}
What annoys me is that if ptr is NULL, then it does
get output as ' 0' instead of
'0x0000000000000000' as I'd like it to print.
Can anyone suggest a solution to this, other than
checking for NULL manually? Casting to int is not an
option since pointers are 8-byte and ints are 4-byte
on my system.
thanks in advance,
- J.