RSS

C++ coding in XCode

19 Jan

For some reason it took me forever to figure out how to use XCode as a C++ compiler. Recently, I figured it out and have worked on several projects without incident. 

I needed a compiler to use on my mac because I am currently taking a class on C++ algorithms that uses Microsoft Visual run on Windows. Not surprisingly, Visual doesn’t run on OSX (and it’s frankly too much effort and processing power to install windows on my mac and then run Visual through that. – possible, but unwieldy.) 

Frankly, once I started using Xcode for C++. I realized that it’s both simpler and better than Visual anyway. Especially for a new user: I’d rather spend my time and energy working in C++ than trying to figure out a complex compiler. So, without further ado…

Protocol:

1. Install XCode on your machine (it’s huge, so plan accordingly)

2. Open XCode and select File > New Project.

3. Select ‘Command Line Tool’ from OSX > Application

Image

4. Give your New Project a name

Image

5. Click Next and select a location to save your file (desktop / developer folder/ etc.)

Image

6.Your New Project will open and you just need to select main.cpp to get the familiar ‘hello world’ skeleton program.

Image

7. I erase the skeleton and replace it with a simple :

int main(){

return 0;

}

and start from there. 

8. In order to to compile and run your program, select Program > Build, correct any errors and Build again if necessary. Then hit the play button in the upper left corner of your window to run the program (intuitive is nice, isn’t it?)

Your program will run, giving you an output window at the bottom of the main window. You may need to click on that window in order to provide input if your program requires it.

I hope this helps you speed along to programming quicker and with less hunting than I had to do. I don’t know why I even tried to find something outside of XCode to start with.  

 
Leave a comment

Posted by on January 19, 2013 in Uncategorized

 

Tags: , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: