Itzik984
Itzik984

Reputation: 16794

Xcode not showing anything in console with C++

I was just trying to use Xcode for a very small C++ project, and wanted to see

some prints in the console, the thing is I did not see anything.

I tried to run a very simple code instead:

#include <iostream>

int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
printf("here");
return 0;
}

but still, nothing in Xcode console.

any idea why?

EDIT:

adding snapshot of the program:

xcode

EDIT 2:

found this,

and it's working:

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

Upvotes: 3

Views: 17817

Answers (5)

Hance Wu
Hance Wu

Reputation: 1

maybe you need to add "\n" after "here" I don't know why but it works for me. Hope someone can explain it for me.

Upvotes: 0

bejoux
bejoux

Reputation: 31

It sounds like when you created a new project (File > New > Project... ), you selected "C/C++ Library". Since libraries don't output to the console directly, that explains why Run was greyed out for you and running it doesn't output to the console.

Instead, you need to create a new project and select "Command Line Tool" template in the Application section, and build your program from there.

Upvotes: 3

bames53
bames53

Reputation: 88215

Your image doesn't show that you ran the program, only that you built it. Look at the Log Navigator (the last one, ⌘7) and see if there are any logs for 'Debug one' after 'Build one'. To run the program use Product > Run or ⌘R.

Upvotes: 2

user1116768
user1116768

Reputation:

Try pressing Shift+Command+R. That should compile your program and open it in a terminal window.

Upvotes: 1

Caleb
Caleb

Reputation: 125007

That should work fine. Are you sure that you had the console displayed? Try command-shift-C or choose View->Debug Area->Activate Console.

If that doesn't help, try running your program from a Terminal window. Does the program display the expected output?

Upvotes: 3

Related Questions