31

I want to write a C++ program in Xcode on my Mac. I wrote this basic one to test it. When I build, I get a "Build Successful" message.

However, I cannot run it! If I hit Command+R nothing happens. When I go to Project->Run the Run option is disabled.

#include <iostream>

using namespace std;

int main()
{

    cout << "helo" << endl;

}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    How did you create the new project. You have to select command line application > C++ Application in the new file dialog. – Alex Nichol Oct 27 '11 at 02:27

1 Answers1

74
  1. Launch XCode
    Step 1
  2. In the "Choose template" box, pick Mac OS X, then Command Line Tool. Press Next
    Step 2
  3. Give your project a name, select C++ as the type
    Step 3
  4. You should see a new project with main.cpp
    Step 4
  5. press the Run button
  6. At the bottom of the screen, under All Output you should see:

    Hello, World!
    Program ended with exit code: 0

phwd
  • 19,975
  • 5
  • 50
  • 78
ObscureRobot
  • 7,306
  • 2
  • 27
  • 36
  • 5
    I just got a "guru" badge for this answer. While nice, I think this is a clear sign that Apple needs to take a careful look at their documentation. – ObscureRobot May 06 '14 at 17:39
  • By default, it creates a `main.cpp` file, which contains a **Hello World** message to print. When I try to add another `C++` file to that project, which prints, say **Foo**, clicking the `Run` button still outputs **Hello World** only. How do I create multiple `C++` files under that project and run them individually, without one referencing or depending upon the others? – SexyBeast May 29 '14 at 21:03
  • @Cupidvogel - that is a good standalone question. Please post it as a question and you are much more likely to get a good answer! – ObscureRobot May 30 '14 at 20:40
  • Any ideas on how to run individual files in a project ? – Harit Vishwakarma Sep 15 '15 at 18:54
  • @iota - another good standalone question. Everyone else - Comments are not the place for questions. Please post new questions and you will get better answers. Additionally, others will be able to find your answers in the future. – ObscureRobot Sep 15 '15 at 21:55
  • 1
    @ObscureRobot posted: http://stackoverflow.com/questions/32604251/mac-what-is-the-best-way-to-have-multiple-c-c-files-in-a-project-and-be-able – Harit Vishwakarma Sep 16 '15 at 09:11
  • @ObscureRobot build failed due to " Showing Recent Issues No signing certificate "Mac Development" found: No "Mac Development" signing certificate matching team ID "*********" with a private key was found." Is it possible to run c++ in Xcode with free personal team? – Sazzad Hissain Khan Mar 03 '18 at 14:23