PDA

View Full Version : C++ newbie wants help




jpmittins
Oct 20, 2008, 10:07 PM
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
Oct 20, 2008, 11:38 PM
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
Oct 21, 2008, 10:13 AM
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:

ChrisA
Oct 21, 2008, 12:58 PM
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

jpmittins
Oct 21, 2008, 02:54 PM
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 (http://www.amazon.com/Starting-Out-Control-Structures/dp/0321545885/ref=sr_1_1?ie=UTF8&s=books&qid=1224618471&sr=1-1) 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
Oct 21, 2008, 03:13 PM
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:

jpmittins
Oct 21, 2008, 03:18 PM
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
Oct 21, 2008, 03:35 PM
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

Cromulent
Oct 21, 2008, 03:43 PM
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?

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

jpmittins
Oct 21, 2008, 03:47 PM
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.