Using C++ on Xcode getting HEX values

Discussion in 'Mac Programming' started by Marioqwe, Apr 7, 2012.

  1. macrumors newbie

    Joined:
    Apr 7, 2012
    #1
    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.
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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
     
  3. thread starter macrumors newbie

    Joined:
    Apr 7, 2012
    #3
    Thanks for replying.
    I have tried these two things,

    Code:
    int main(int argc, char *argv[]) {
    std::cout<<16<<std::endl;
    return 0;
    }
    
    Code:
    160x7fff7e71af78
    Code:
    int main(int argc, char *argv[]) {
    std::cout<<"HOLA   "<<std::cout;
    return 0;
    }
    
    Code:
    HOLA   0x7fff7e71af78
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    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.
     
  5. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    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
     
  6. thread starter macrumors newbie

    Joined:
    Apr 7, 2012

Share This Page