New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Apps and Games Discussion of applications and games available for Mac OS X.

C++ Programming with XCode 2


Post Reply New Thread Subscribe

 
Thread Tools
novicew

 
novicew's Avatar
 
Member Since: Jan 04, 2006
Location: Hamburg, Germany
Posts: 1,385
novicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to all
Mac Specs: MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)

novicew is offline
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.
QUOTE Thanks
johninc

 
johninc's Avatar
 
Member Since: Dec 28, 2004
Location: Albany, CA
Posts: 643
johninc is on a distinguished road
Mac Specs: ibook G4 12 inch running mac os 10.4 with: 60 gb HD+256 mb ram+Radeon 9200

johninc is offline
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?
QUOTE Thanks
lil
Guest
 
Posts: n/a

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
QUOTE Thanks
novicew

 
novicew's Avatar
 
Member Since: Jan 04, 2006
Location: Hamburg, Germany
Posts: 1,385
novicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to all
Mac Specs: MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)

novicew is offline
Quote:
Originally Posted by lil
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:
QUOTE Thanks
lil
Guest
 
Posts: n/a

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
QUOTE Thanks
novicew

 
novicew's Avatar
 
Member Since: Jan 04, 2006
Location: Hamburg, Germany
Posts: 1,385
novicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to all
Mac Specs: MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)

novicew is offline
Great! it works.

Thank you very much for the tip.
QUOTE Thanks
novicew

 
novicew's Avatar
 
Member Since: Jan 04, 2006
Location: Hamburg, Germany
Posts: 1,385
novicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to all
Mac Specs: MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)

novicew is offline
Can you figure out what I am doing wrong here ?.

Thank you in advance
QUOTE Thanks
GrubeMasterFlex

 
Member Since: Sep 24, 2009
Posts: 1
GrubeMasterFlex is on a distinguished road

GrubeMasterFlex is offline
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?
QUOTE Thanks

Post Reply New Thread Subscribe


« Werid AIM Issue | Calendar Integration - Mac/PC/BusyCal/Iphone/MobileMe/Google »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Newbie programmer needs JAVA help in XCODE zeroelink OS X - Development and Darwin 1 02-02-2006 12:42 PM
Features I miss from Visual Studio, now using xCode... RChickenMan OS X - Development and Darwin 0 10-18-2005 12:14 PM
XCode Include path problem Jove OS X - Development and Darwin 0 03-18-2005 10:41 AM
c++ editor - xcode Kleb OS X - Development and Darwin 1 08-14-2004 01:45 AM
New Xcode plug-in helps developers reuse code Murlyn OS X - Development and Darwin 0 11-10-2003 01:16 PM

All times are GMT -4. The time now is 12:54 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?