C++ Programming with XCode 2

Joined
Jan 4, 2006
Messages
1,385
Reaction score
146
Points
63
Location
Hamburg, Germany
Your Mac's Specs
MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
I am pretty new to Apple and trying to write my first c++ program on XCode platform. However due to it's complexity I am kind of stuck not knowing from where to start with. I would really appreciate if someone can explain me how to do that.

#include<iostream>
using namespace std;
int main()
{
cout <<"Hello World!\n";
cin.get();
}

By the way, I had no problem running it on Terminal.

Thank you in advance.
 
Joined
Dec 28, 2004
Messages
643
Reaction score
5
Points
18
Location
Albany, CA
Your Mac's Specs
ibook G4 12 inch running mac os 10.4 with: 60 gb HD+256 mb ram+Radeon 9200
C++ works in Xcode!?!?!?!?! and Terminal?!?!?!?
AWESOME!!!
sorry I couldn't answer your question, did you try it the same way you did it on a pc?
 
L

lil

Guest
When you say it worked in the terminal, you mean you compiled the application, ran it from the terminal and it worked but not from double clicking it in Finder?

How exactly have you gone about compiling it so far?

There are particular ways of doing this.

Also you may want to look into Objective C as this is what Mac OS X and the Cocoa APIs make the most use of.

C++ can be compiled in XCode because it relies on the gcc (GNU C Compiler) engine which can compile C++ code.

Vicky
 
OP
novicew
Joined
Jan 4, 2006
Messages
1,385
Reaction score
146
Points
63
Location
Hamburg, Germany
Your Mac's Specs
MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
lil said:
When you say it worked in the terminal, you mean you compiled the application, ran it from the terminal and it worked but not from double clicking it in Finder?

How exactly have you gone about compiling it so far?

There are particular ways of doing this.

Also you may want to look into Objective C as this is what Mac OS X and the Cocoa APIs make the most use of.

C++ can be compiled in XCode because it relies on the gcc (GNU C Compiler) engine which can compile C++ code.

Vicky

Hi Vicky

Yes. I did manage to compile and run it from the Terminal. All the steps I followed are listed in my Blog. My problem is to run a pre-coded *.cpp files in XCode 2. Imagine you have a hello.cpp file which you wrote in a text editor and you want to compile and run it in XCode 2. I could open the *.cpp file in XCode but there was no "Button" to Compile or to Run it. May be there is a way but I am missing the pieces. :dive:
 
L

lil

Guest
Ok, here's wotcha need to do :flower:

Load XCode, then click File -> New Project

Scroll down the project type lists down to the 'Command Line Utility' section.

Expand it if necessary clicking the arrow. Select C++ Tool

Select a destination for the new project and a name in the next step. (Having clicked Next after selecting C++ Tool)

Then you will get the project browser up, double click main.cpp and up pops XCode's editor.

Pop your code in there e.g.:
--
#include <iostream>
using namespace std;
int main (int argc, char * const argv[])
{
cout <<"Hello World!\n";
return 0;
}
--

Then save, and click Build and Go in the toobar. Voila :flower:

However, definitely check out the developers documentation, it truly is excellent.

Vicky
 
OP
novicew
Joined
Jan 4, 2006
Messages
1,385
Reaction score
146
Points
63
Location
Hamburg, Germany
Your Mac's Specs
MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
Great! it works.

Thank you very much for the tip.
 
OP
novicew
Joined
Jan 4, 2006
Messages
1,385
Reaction score
146
Points
63
Location
Hamburg, Germany
Your Mac's Specs
MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
Can you figure out what I am doing wrong here ?.

Thank you in advance
 
Joined
Sep 24, 2009
Messages
1
Reaction score
0
Points
1
Unfortunately I was unable to Run any cpp program, only Build successfully. The Build and run button is dim, but i can build using the command command-shift-B. nothing works in the console under Run nor in the Terminal.
I started my program from scratch via New program - New file - cpp.
any Ideas?
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top