user1443548
user1443548

Reputation: 71

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. Here is a screenshot of what I have:

enter image description here

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?

Upvotes: 7

Views: 1402

Answers (2)

bames53
bames53

Reputation: 88215

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.

Here is what it will look like when you run the program: Finished running

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. 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. 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.

Upvotes: 5

Superman
Superman

Reputation: 3081

Put a breakpoint at the return statement or a getchar() before return. 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.

Upvotes: 3

Related Questions