PDA

View Full Version : Using C++ on Xcode getting HEX values




Marioqwe
Apr 7, 2012, 08:53 PM
Hello,

Earlier today I tried to compile a simple program but I started getting HEX values for a number of things. For example, when I try to get a blank space, I get the following " 0x7fff7e71af78" with the space in front. When I try to get the number 16, I get "160x7fff7e71af78."

I'd really appreciate if somebody lets me know how to fix it.



lee1210
Apr 7, 2012, 08:58 PM
You'll need to be more specific than "for a lot of things". Is this appearing in output generated with cout? Can you show some compliance sample code? Generally you get hex values when you ask for them or when you inadvertently display a pointer.

-Lee

Marioqwe
Apr 7, 2012, 09:11 PM
Thanks for replying.
I have tried these two things,


int main(int argc, char *argv[]) {
std::cout<<16<<std::endl;
return 0;
}


160x7fff7e71af78


int main(int argc, char *argv[]) {
std::cout<<"HOLA "<<std::cout;
return 0;
}


HOLA 0x7fff7e71af78

chown33
Apr 7, 2012, 09:17 PM
int main(int argc, char *argv[]) {
std::cout<<16<<std::endl;
return 0;
}


160x7fff7e71af78


int main(int argc, char *argv[]) {
std::cout<<"HOLA "<<std::cout;
return 0;
}


HOLA 0x7fff7e71af78
I've hilited some important differences in red.

Personally, I don't believe the first output was actually produced by the first posted code. The address printed for the first output is identical to that printed for the second output. Instead, I suspect the posted first output was produced by something more like the second posted code.

lee1210
Apr 7, 2012, 09:36 PM
Just to pile on, being that the addresses are the same in both examples it seems that this is a pointer to the same object, so you likely had std::cout as the last operand to << in both cases. You may have miscopied the code, failed to recompile at some point in your tests, etc. the moral here is that passing the object std::cout to its own << operator appears to print its address.

Basically, what changed is you started using the wrong operand. std::endl should be fine.

-Lee

Marioqwe
Apr 7, 2012, 09:41 PM
I see my mistake. How silly. Thank You.