如何在 Xcode 4 中运行 C++ 程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7911076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 17:42:10  来源:igfitidea点击:

How do I run a C++ program in Xcode 4?

c++xcodemacosxcode4

提问by ObscureRobot

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.

我想在我的 Mac 上用 Xcode 编写一个 C++ 程序。我写了这个基本的来测试它。构建时,我收到“构建成功”消息。

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

但是,我无法运行它!如果我按 Command+R 没有任何反应。当我转到 Project->Run 时,Run 选项被禁用。

#include <iostream>

using namespace std;

int main()
{

    cout << "helo" << endl;

}

回答by ObscureRobot

  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

  1. 启动 XCode
    第1步
  2. 在“选择模板”框中,选择 Mac OS X,然后选择命令行工具。按下一步
    第2步
  3. 为您的项目命名,选择 C++ 作为类型
    第 3 步
  4. 你应该看到一个带有 main.cpp 的新项目
    第四步
  5. 按下运行按钮
  6. 在屏幕底部的所有输出下,您应该看到:

    你好,世界!
    程序以退出代码结束:0