Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

204467

macrumors 6502a
Original poster
Jul 13, 2008
821
0
Philadelphia, PA
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.
 

Aranince

macrumors 65816
Apr 18, 2007
1,104
0
California
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.
 

hankolerd

macrumors 6502
Sep 19, 2007
353
6
Seattle, WA
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 http://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:
 

ChrisA

macrumors G5
Jan 5, 2006
12,919
2,173
Redondo Beach, California
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.

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
 

204467

macrumors 6502a
Original poster
Jul 13, 2008
821
0
Philadelphia, PA
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?
 

hankolerd

macrumors 6502
Sep 19, 2007
353
6
Seattle, WA
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.

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:
 

204467

macrumors 6502a
Original poster
Jul 13, 2008
821
0
Philadelphia, PA
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:

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?
 

hankolerd

macrumors 6502
Sep 19, 2007
353
6
Seattle, WA
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
 

204467

macrumors 6502a
Original poster
Jul 13, 2008
821
0
Philadelphia, PA
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

It is just a text file saved with a cpp extension. Any text editor will do.

Thank you both. I will read that article when I have the time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.