如何在 Xcode 输出控制台中显示 C++ 输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10518430/
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-27 14:10:34  来源:igfitidea点击:

How to display C++ output in Xcode output console

c++xcode

提问by William

I have read all prior answers to similar questions and they all seem to pertain to displaying output for a Command Line project. What if you'd like to run as what Xcode calls a 'Empty' (project with no files, targets or build configs).

我已经阅读了类似问题的所有先前答案,它们似乎都与显示命令行项目的输出有关。如果您想以 Xcode 称为“空”的方式运行(没有文件、目标或构建配置的项目),该怎么办?

The code below builds successfully. And yet the 'All Output' console still does not show the results. I tried to go deep into the GDB documentation but I'm a newbie and I get lost in it.

下面的代码构建成功。然而“所有输出”控制台仍然没有显示结果。我试图深入研究 GDB 文档,但我是一个新手,并且迷失在其中。

Below is the code:

下面是代码:

#include <iostream>                           
using namespace std;  
int main()                                    

{                                             

cout << "Come up and C++ me some time.";  
cout << endl;                             
cout << "You won't regret it!" << endl;   
std::cout << "Press any key to continue." <<endl;
cin.get();
cin.get();

return 0;      
}

What makes it worse is that the teacher of my C++ class has no solution for this after 3 attempts.

更糟糕的是,我的C++课的老师在尝试了3次之后没有解决这个问题。

回答by Aligus

Try Activate Console command: Cmd+Shift+Cor in the Top menu: View -> Debug Area -> Activate Console. It is true for Xcode 4.3.2.

尝试激活控制台命令:Cmd+ Shift+C或在顶部的菜单:视图- >调试区- >激活控制台。Xcode 4.3.2 确实如此。

As I remember there is a command Cmd+Shift+R(run in console) in Xcode 3.

正如我记得有一个命令Cmd+ Shift+R在Xcode 3(在控制台运行)。

回答by shazzing

Few things first.

先说几件事。

Xcode is used for multitude of development from mobile-app to a basic console application(which as I understand is your case).

Xcode 用于从移动应用程序到基本控制台应用程序的大量开发(据我所知,这是您的情况)。

Xcode knows to associate I/O with your OSX/Xcode console when you create a New Project -> template of OS X -> application and console. (the OSX console may be default I/O for number of other framework, but obviously is the default one for the above).

当您创建新项目 -> OS X 模板 ->应用程序和控制台时,Xcode 知道将 I/O 与您的 OSX/Xcode 控制台相关联。(OSX 控制台可能是其他框架的默认 I/O,但显然是上述框架的默认 I/O)。

Another important thing(which you are already doing) as someone mentioned. Xcode does not log to console until it sees "endl" or "\n".

有人提到另一件重要的事情(你已经在做)。 Xcode 不会登录到控制台,直到它看到 "endl" 或 "\n"

回答by had the same problem

My post may be way tardy, but if any other noob users scours the web like I did for an hour before working out the answer on their own it will be a godsend. The answer was simple but no one mentioned it. Make the window wider after activating the debug area!!!

我的帖子可能会迟到,但如果任何其他菜鸟用户像我一样在网上搜索一个小时,然后自己找出答案,那将是天赐之物。答案很简单,但没有人提到。激活调试区后使窗口变宽!!!

If the xcode window is too narrow, i.e. if you have a webpage open showing a tutorial on C++ and squished the xcode window next to it like I did, and you don't see the command line output despite activating the debugger because when the window is narrow the stupid xcode hides the left half of the debugger if both the right and left panels are currently visible (as is default it seems). These can be toggled off in the upper right corner. Alternatively the bottom left corner of the debugger pane has two buttons that lets you select which half of the debugger to view, the command line portion or the other portion.

如果 xcode 窗口太窄,即如果您打开了一个显示 C++ 教程的网页,并像我一样挤压了旁边的 xcode 窗口,并且尽管激活了调试器,您也看不到命令​​行输出,因为当窗口如果左右面板当前都可见(看起来是默认的),那么愚蠢的 xcode 会隐藏调试器的左半部分。这些可以在右上角关闭。或者,调试器窗格的左下角有两个按钮,可让您选择要查看的调试器的哪一半,命令行部分或另一部分。

If you're a noob user like me, then this just might save you an hour headache.

如果您是像我一样的菜鸟用户,那么这可能会为您节省一个小时的头痛。

回答by Stoff81

It seems you have to have "\n" at the end of your prints. Like so:

似乎您的打印件末尾必须有“\n”。像这样:

cout << "Come up and C++ me some time.\n";

That should sort it.

那应该排序它。