Xcode 5没有控制台输出C ++代码

时间:2014-08-02 05:42:14

标签: c++ xcode

在Xcode 5控制台窗口中编译我的C ++代码时遇到问题。

程序没有错误,我使用Xcode中的命令行工具和下拉菜单中的选定C ++创建了项目文件。

默认" Hello World"程序显示输出但是我在下面写的代码没有显示任何内容。

我跑步时得到的是" Build Succeeded"。

我是否缺少任何必需的工具,有人可以解释如何正确设置IDE吗?

#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

void read(std::istream& in, std::vector<std::string>& text)
{
   std::string line;
   while (std::getline(in, line))
      text.push_back(line);
}

int main(int argc, char * argv[])
{

    // Read the entire input into text. If the command line names a file,
    // read that file. Otherwise, read the standard input.

    std::vector<std::string> text; ///< Store the lines of text here

    if (argc < 2)
       read(std::cin, text);
    else
    {
       std::ifstream in (argv[1]);
       if (not in)
       {
           std::perror(argv[1]);
           return EXIT_FAILURE;
       }
       read(in, text);
    }

   // Part 2. Sorth the text.
   std::sort(text.begin(), text.end());

   // Part 3. Print the sorted text.
   std::copy(text.begin(), text.end(),
             std::ostream_iterator<std::string>(std::cout, "\n"));
   return 0;
}

1 个答案:

答案 0 :(得分:0)

看起来你对我来说一切都是正确的。为了使它工作我所做的是在输出框中输入几行,然后按回车键,然后按Ctrl + D,(除非你在新行的开头按它,否则Ctrl + D命令不起作用)然后程序按预期运行。