简体   繁体   English

我成功地能够在C ++中运行Hello World程序,但是我无法看到并输出。 它在哪里?

[英]I successfully am able to run a Hello World program in C++, but I can't see and output. Where is it?

I am a complete beginner. 我是一个完全的初学者。 I just downloaded xCode today. 我今天刚刚下载了xCode。 Here is a screenshot of what I have: 这是我的截图:

在此输入图像描述

As you can see, I successfully ran the program, however, I can't see any out put anywhere. 正如你所看到的,我成功地运行了程序,但是,我无法看到任何输出。 Where is it and how do I see it? 它在哪里,我怎么看?

It does not look like the program has run at all, only built. 看起来程序根本没有运行,只是构建了。 The status up at the top says build succeeded, not run succeeded. 顶部的状态表示构建成功,而不是成功运行 Command-R will run the program. Command-R将运行该程序。

Here is what it will look like when you run the program: 以下是运行程序时的样子: 跑完了

Also you can use the Log Navigator to go and see results from previous build and debug sessions. 您还可以使用Log Navigator查看以前的构建和调试会话的结果。 日志导航器

You will often see tutorial programs written for Windows where the program ends with asking the user for input. 您经常会看到为Windows编写的教程程序,程序结束时会要求用户输入。 The reason for this is that the console model on Windows has the program owning the console window, so the window will disappear as soon as the program exits. 原因是Windows上的控制台模型具有拥有控制台窗口的程序,因此一旦程序退出,窗口就会消失。 So by asking for input as the last thing the program will keep running until the user gives it that input, whereupon it the program will complete and the console window will disappear. 因此,通过要求输入作为程序将继续运行的最后一件事,直到用户给它输入,然后程序将完成并且控制台窗口将消失。

Non-Windows platforms don't behave this way and generally do not require such code. 非Windows平台不会以这种方式运行,通常不需要此类代码。

Put a breakpoint at the return statement or a getchar() before return. 在return语句或getchar()之前放置一个断点。 The reason you're not seeing the output is because the console closes when the program exits. 您没有看到输出的原因是因为控制台在程序退出时关闭。 So the above points prevent the program from ending. 所以上述几点阻止了程序的结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM