C++ newbie wants help

Discussion in 'Mac Programming' started by 204467, Oct 20, 2008.

  1. 204467 macrumors 6502a

    204467

    Joined:
    Jul 13, 2008
    Location:
    Philadelphia, PA
    #1
    Though I never thought I would call myself that. I'm thinking of teaching myself C++; anyone have any good books on how to learn it they would recommend? Also, can you suggest a good compiler (that's how you write code, correct?) that works on the Mac platform? Preferably free (the compiler, not the book). Thanks.
     
  2. Aranince macrumors 65816

    Joined:
    Apr 18, 2007
    Location:
    California
    #2
    Books are good, you could also read the tutorials at cprogramming.com. As for compiler, you can use XCode for C/C++.

    If you don't want to use XCode, you use the Terminal and use gcc if you really want to. You do need to install XCode to get gcc. For writing the code without XCode, I would recommend VIM or MacVim.
     
  3. hankolerd macrumors 6502

    hankolerd

    Joined:
    Sep 19, 2007
    Location:
    Seattle, WA
    #3
    I use Xcode. You can install it off of your Mac OS X dvd(If you don't already have it installed). For a year or two I just used Xcode to type out my code, and used gcc in the terminal to compile it. Now I build c++ projects in Xcode and compile it straight through Xcode. If you ever want a site to look up common classes and objects in c++ I highly recommend www.cplusplus.com They list all different data structures and have examples of how to use them, I go there at least once a week to look something up. Good luck! :apple:
     
  4. ChrisA macrumors G4

    Joined:
    Jan 5, 2006
    Location:
    Redondo Beach, California
    #4
    Mac OS X ships with a C/C++/Objective C compiler. xcode is a GUI application that wraps the compiler and other tools in a user interface. You can also access the compiler from the command line. If you are just starting out use the command line. Later when the projects are more complex maybe use xcode.

    Book: I think the "standard" is "C++ How to Program" by Deitel & Deitel
     
  5. 204467 thread starter macrumors 6502a

    204467

    Joined:
    Jul 13, 2008
    Location:
    Philadelphia, PA
    #5
    Okay, so a compiler is what takes any code you've written and processes it and turns it into an executable program (pardon the crudeness of that description, like I said, I'm extremely new at this). Is that what XCode is? How do you get to that? I'm kind of (bit of an understatement) lost here. By the way, does anyone have any experience with this book? It got better reviews than the one by Deitel that was mentioned earlier. Only thing is I can't really justify spending $92 dollars on a paperback book (oh boy, will college be a nasty surprise...). Maybe if I could find it for cheap on eBay. Any more advice?
     
  6. hankolerd macrumors 6502

    hankolerd

    Joined:
    Sep 19, 2007
    Location:
    Seattle, WA
    #6
    You are correct about what the compiler is.
    Xcode is a program that is a powerful text editor(what you will write the code in) and can compile your programs with the click of a button. When you create a c++ file(.cpp) it should automatically open it using Xcode. I would start there, and use Xcode to edit your files, and then open up terminal and use g++ to compile them.
    When you get into more complex programs that require multiple classes and files, then use Xcode to create a project, this is where you will be able to click a button and have it automatically build and execute. You could skip straight to this step, but it is important to know how to command line compile your program and it will help you understand it all better.
    Xcode can be found under Max OS X->Developer->Applications->Xcode
    If you do not have the developer folder it is because you have not installed it off of your Max OS X disk yet. Insert the disk and look around for the installer for the developer tools. :apple:
     
  7. 204467 thread starter macrumors 6502a

    204467

    Joined:
    Jul 13, 2008
    Location:
    Philadelphia, PA
    #7
    Very helpful! Only one thing; how do you create a .cpp file? Is it when you write some code in Xcode and save it as such? Or is it something else?
     
  8. hankolerd macrumors 6502

    hankolerd

    Joined:
    Sep 19, 2007
    Location:
    Seattle, WA
    #8
    Open up Xcode, go to File->New File... on the left pane you should see an iPhone OS category and a Mac OS X category, under the Mac OS X category select 'C and C++', under the templates that are shown, select 'c++ file'.
    Also, you could just save a text file as a .cpp file instead of a .txt.
    Here is a some info on Xcode and Apples other Developer Tools if you are interested. :apple:
    http://developer.apple.com/technology/tools.html
     
  9. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    It is just a text file saved with a cpp extension. Any text editor will do.
     
  10. 204467 thread starter macrumors 6502a

    204467

    Joined:
    Jul 13, 2008
    Location:
    Philadelphia, PA
    #10
    Thank you both. I will read that article when I have the time.
     

Share This Page