New to programming, need help setting up for C++ in xcode

Discussion in 'Mac Programming' started by BrendanSJCI, Oct 24, 2006.

  1. BrendanSJCI macrumors newbie

    Oct 24, 2006
    I downloaded the newest version of xtools so I could follow along in a book about C++. The last time I did anything in the book was over 5 years ago, and my dad just set up the software I needed to do the examples in it.

    I made a blank C++ document, and it asked if I wanted to make a corresponding ".h" file, which I declined. Is this where the definitions for certain functions are stored? If so, is that the file I should refer to in my headers? The book says, for example, Borland C++ uses IOSTREAM.H for stream-related definitions, while Microsoft Visual C++ uses other headers in addition to that; how does it work in xcode?

    In addition to not knowing that, I'm not really sure how to test the code that I'm putting in. I get the general idea of the targets, but I don't know which to choose or how to set them up.

    If anyone could guide me through setting up xcode to let me work through this book that would be a great.
  2. gnasher729 macrumors P6


    Nov 25, 2005
    For beginners, best to start with "New Project", then in the assistant scroll down to "C++ tool". That produces a complete program that doesn't do much, press Command-R to run it, then you can start adding things.
  3. kainjow Moderator emeritus


    Jun 15, 2000
    There should be made a stickie about C++ and Xcode because this gets asked a few times a week...
  4. BrendanSJCI thread starter macrumors newbie

    Oct 24, 2006
    Thanks for the help getting running. Sorry for asking a common question, but a search for "C++" didn't turn up anything.

    The book I'm using is from 1994 so I've had to change some things around. This bit of code is giving me two errors that I can't figure out;

    #include <iostream>

    using namespace std;

    int main(int)
    int number = 1001;

    cout << "Decimal: " << number << "\tHexidecimal: " << hex << number << endl;

    cout << "Decimal: " << dec << number << "\tOctal: " << oct << number << endl;

    the errors are:
    "'number' was not declared in this scope"
    "expected ';' before 'std'"

    Could some one clear this up for me?
  5. YoNeX macrumors regular


    Apr 29, 2005
    What values does oct, dec, and hex have. They don't seem to be declared and/or intialized.
  6. BrendanSJCI thread starter macrumors newbie

    Oct 24, 2006
    From what I understand, they manipulate the number so as to display it in hexidecimal, octal, and decimal. The next example does the same thing but uses setbase() and <iomanip>. That program has errors too, which I suspect are from me trying to translate from a pre-asni/iso book. I'm thinking of getting a new book so I can focus on what they're trying to show me rather than tracking down bugs.
  7. gnasher729 macrumors P6


    Nov 25, 2005
    I recommend getting rid of "using namespace std" and using std::cout, std::dec and so on. The cost of typing five characters is minimal compared to the cost of having to figure out what your code means. And you don't run into nasty surprises if you add another variable like "int hex = 0x1234;" in your program.
  8. BrendanSJCI thread starter macrumors newbie

    Oct 24, 2006
    Thanks, getting rid of "using namespace std" fixed it.

Share This Page