Xcode not showing anything in console with C++

↘锁芯ラ 提交于 2019-12-23 17:40:59

问题


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:

EDIT 2:

found this,

and its working:

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


回答1:


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.




回答2:


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?




回答3:


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.




回答4:


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




回答5:


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.



来源:https://stackoverflow.com/questions/9576258/xcode-not-showing-anything-in-console-with-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!