running C++ program on xcode - c++

when I run a simple C++ program on Xcode, the compiler says it's built successfully, but there is no output. how can I make the result show up? thanks!

Cmd-Enter is the default "build and run" keyboard hotkey. Once you've pressed that, use Cmd-Shift-R to open the console and see your program's output.

in the tab Groups and file, under the xcode icon of your project there are 3 folders, Source, Documentation, Products, under Products there is your executable.
hth

Related

Qt Application not running

I am trying to run a simple "Hello, world" console application but I am experiencing some errors when compiling that I am not familiar with. I have done a bit of research into similar problems with Qt but I haven't been able to find a solution. The closest solution I have come across was to change my Patch Command setting under:
Preferences -> Environment -> System -> Patch Command
to
usr/bin/xterm -e
However, when I try to do this it goes red indicating that I do not have this file.
Environment Preferences Window
The following image is a screenshot of what is displayed in the terminal window when attempting to compile my project.
Console Application Output
Any help on this problem would be much apprectiated! It is very frustrating having something like this hold me back!
Don't run your project in a terminal unless you actually select a working terminal, and that's all. The patch command is irrelevant in this anyway - it's not the terminal, but the patch command -- used to patch source code. You don't need it unless you explicitly use code patching. Go to Projects (Ctrl-5), click on the active Run configuration for your project, uncheck "Run in terminal", done.

visualstudio code C++ terminal for output

When debugging a C++ application on linux using, VisualStudio Code, an instance of an external terminal window is opened, and the applications console appears on this window.
This is a bit inconvenient because I have to change windows to see the output when debugging.
Is it possible to have the output to appear in a "pane" like the built in terminal appears (like the one started by CTRL-`)? If so how can this be done?
I have tried changing the launch file's "externalConsole" from true to false but this didn't work.
You need to use the Integrated Terminal.
View > Toggle Integrated Terminal
In launch.json set "externalConsole": false,.
Then the output goes to the Debug Console.
But instead of things looking like:
Hello World!
It will show up as:
#"Hello World!\r\n"
I have read that they still work in proper terminal support for the terminal inside VSCode. I think that also explains why it defaults now to the external terminal.

How to execute a CLion program in gnome terminal?

This question already has an answer here but I am using CLion version 1.2.1 and the answer in that post doesn't help. It is possible to run a CLion program in gnome terminal instead of its own console ? If yes, how ? Thanks.
EDIT : I know where the executable file are stored but want to know if it is possible to run the file in terminal directly from the ide i.e. by selecting the run option in ide.
Yes, you can execute a Clion c/c++ program in a gnome terminal from the IDE. Here is how:
In the top right of your clion application you should see your project name or "Build All". Click on that and go to "edit configurations"
there click on the plus sign(top left) and then on "Application"
Now go to "Executable:" and click on "select others". There you should go to where your gnome-terminal is stored (mine is at "/usr/bin/gnome-terminal" on ubuntu)
Next go to "Program arguments:" and type -e ./myProjectName (For newer versions of gnome-terminal -e is deprecated, use -- ./myProjectName)
go to "Working Directory:" and type in the location to your cmake-build-debug folder found in your project folder
You can now press okay and go to the top right to select the name of your application that you created in step 2
This will run your program in the gnome terminal.
Hope this helped :)

Eclipse runs old code even after building the new one

I started to study c++ and i choosen Eclipse IDE for it.
I need some basic instructions.
Even after i compile my code with ctrl+b Eclipse shows me the old "Hello World" program in console. If i look up the compiled .exe files in my projects "Release" folder i can ran my new program very well.
For some reason Eclipse does not refresh output console.
Any ideas?
Have you tried checking that there are not still multiple consoles open. On the console tab try clicking the Display Selected Console button, or pushing the red terminate button until it becomes greyed out and then running it again.
I saw at the output console's setting's that it is showing my project's Debug release.
So i searched for the compiled in my Debug folder and i saw it was the old .exe of my project.
After that i did the same thing within the Release folder that was the new code!
So all i did was changed the run configuration to Release, pic below.
And now it is working.
Just clean the project from menu...

Can't run programs on my mac

I've been programming on windows for about three months now and when my computer finally died I bought a mac. I'm really happy with it except I can't figure out how to run my c++ programs.
On windows it would open up in command prompt so I figured it would do the same thing except with terminal.
After I write my programs (in Xcode) I can compile them and it'll tell me if there are syntax errors but the run and run related buttons are all Grey and unusable.
It's incredibly annoying that I can't see how the program that I put 4 hours into runs and even more annoying that I don't know if I've made a runtime error. Someone please help.
Thank you very much, James
Assuming that you're trying to write a program that you interact with on the command line, you want to create a "Command Line Tool" project, found under "Application" in the Mac OS X section of the New Project dialog. Choose "C++ stdc++" from the "Type" dropdown, as well. This will give you a main.cpp that should look familiar to you, with a "Hello, World!" sample.
Note that when you Run this program, it might appear to do nothing - You need to open the Console (from the Run menu, or shift+command+R) to see your output.
Xcode deals in projects. If you're just opening the source file, there is no project. Create a project with the files in it and Xcode should let you run it.
Alternately, you can just use G++ on the command line to compile your files and run the resulting executable there.
Try compiling from the terminal as stated above. The a.out file should be created, and should run as long as Xcode has been installed. It should work fine from the terminal, and point out any errors in the compiler's output.
To runs the a.out file, ensure you are in the files directory in terminal and type ./a.out