Results 1 to 8 of 8
  1. #1

    novicew's Avatar
    Member Since
    Jan 04, 2006
    Location
    Hamburg, Germany
    Posts
    1,385
    Specs:
    MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
    C++ Programming with XCode 2
    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.

  2. #2

    johninc's Avatar
    Member Since
    Dec 28, 2004
    Location
    Albany, CA
    Posts
    643
    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?

  3. #3
    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

  4. #4

    novicew's Avatar
    Member Since
    Jan 04, 2006
    Location
    Hamburg, Germany
    Posts
    1,385
    Specs:
    MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
    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:

  5. #5
    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

  6. #6

    novicew's Avatar
    Member Since
    Jan 04, 2006
    Location
    Hamburg, Germany
    Posts
    1,385
    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.

  7. #7

    novicew's Avatar
    Member Since
    Jan 04, 2006
    Location
    Hamburg, Germany
    Posts
    1,385
    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

  8. #8


    Member Since
    Sep 24, 2009
    Posts
    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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Programming C on Xcode
    By MartaC in forum OS X - Development and Darwin
    Replies: 0
    Last Post: 01-23-2012, 08:53 PM
  2. How to start c-programming in xcode? (student on mac)
    By vidarski in forum OS X - Operating System
    Replies: 3
    Last Post: 09-02-2011, 11:28 AM
  3. Programming in xcode
    By katlb in forum Switcher Hangout
    Replies: 1
    Last Post: 01-21-2011, 09:07 PM
  4. New to programming. Having trouble with Xcode
    By Chris23 in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 11-23-2010, 07:51 PM
  5. Programming basic C in Xcode
    By DrQuincy in forum OS X - Development and Darwin
    Replies: 4
    Last Post: 01-16-2008, 04:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •