Can't run programs on my mac - c++

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

Related

how do I run my code on cmd instead of vscode's internal terminal

everyone. I'm kind of new in this field. So bear with it. I'll try to be as specific as I can:
let's say when I run a code(c++ file) in VScode it runs that code on VScode's internal terminal..like this => VScode
but I want that code to run on my Window's CMD like "CodeBlocks" software. Like this => CodeBlocks
but I don't know how to do it in VScode. I mean, when I click on 'run' button it should execute that code on CMD. I tried many ways but it's not working. Help please and thanks in advance.
VSCode has a built-in terminal. That is why in the first case(first image in your question) you see the output as it is. If you don't want to use the built in terminal provided by VSCode then i suggest you open a standalone/separate terminal. And then cd into the project you want to build/compile and then compile the program from there.
Basically, open a terminal externally then go(cd) to your workspace folder and finally compile and run in the external terminal.

Windows cannot find MinGW

I am trying to install MinGW and add it to my PATH on my Windows 10 computer (I need to be able to compile C++ in Atom, in case this is relevant to the answer). As far as I can tell, it is successfully installed and added to my PATH. I know it is added because when I change it to make it wrong, I get an error in Atom. Also, every tutorial I can find on adding it to my PATH says the things that I did. In cmd, when I type gcc, nothing happens. No output, no error message. Only a space, like hitting return twice in a text editor. However, in Atom, when I try to compile and run, nothing happens. No output or error message. compile/run result The picture is of what happens when I try to compile and run.
Can someone tell what I am doing wrong? Thanks!
Note: I am not a beginner, so my lack of output is not user error. Also, I can run the same program without a problem on a Mac.
It sounds like your system is resolving gcc to a different executable than expected.
From a cmd prompt, try where gcc and if the path doesn't look right, then that is a good place to start. If it does look right, then I suggest using a tool like sysinternals procmon.exe. Set the filter to just gcc.exe and then run the gcc command from the cmd prompt and see what the procmon output is.

Strange behavior of Eclipse Neon

I use Eclipse with CDT plugin for my C/C++ development. And I use MinGW compiler. Environment Path set properly. All the setting done properly in Eclipse. While editing the source code its working fine but after compilation when I try to execute the source code sometimes it says it cannot open the .exe file or sometimes doesn't show anything when there is some input to take. When I stop the execution pressing the red button program gets executed completely with default values.
But everything is fine if I compile and run the same source code using notepad and the command prompt. Please help.
A common problem is that if the program is currently executing, the program file is opened by the system and cannot be reopened for writing by the compiler (or more exactly by the linker). This problem can be easily reproduced by starting the program in debug mode and stop it at a breakpoint. Then, while the process is active, change a line in source and ask for a new build: you will get the error saying that the exe file cannot be opened.
How to fix: ensure to close any possible execution of the program when the error happens and rebuild

Build systems in Sublime Text

I'm just beginning to learn programming (on C++ and Python), and by beginning I mean total beginning ("hello world" beginning...). Not wanting to use multiple IDE's, I would like to be able to code and build–simple–programs with my text editor, Sublime Text 2. Could someone indicate me, with a step-by-step tutorial, how to implement C++ and Python compiling and executing capabilities in Sublime Text.
I've searched Sublime Text build systems on the site, but the answers are very specific and can't help a rookie like me (but they'll probably help me later).
Thanks
Sublime Text 2 already comes with scripts for building and running Python and C++ programs.
Simply press Cmd+B (or Ctrl+B on Windows & Linux) when a .py or .cpp file is open. The Python file will automatically execute and show the result in the built in console.
For C++, you need to press Cmd+Shift+B (Ctrl+Shift+B on Windows & Linux) to run it after building.
You need to have Python installed (get it here for Windows), and also a C++ compiler. The build system for C++ tries to call g++ by default (get it here for Windows. Remember to select the C++ compiler when installing!).
You will need to add the directories to path (c:\python32\ or similar for python, c:\mingw\bin or similar for the C++ compiler).
On windows, you may experience problems running the C++ programs (it tries to use bash). But Ctrl+B builds the program, and you can then use a command line to run it. Python works flawlessly on Windows.
windows(install minigw, python2.7 and added to the system path)
cpp:
build: ctrl+b
run: ctrl+shift+b
python:
build and run: ctrl+b
you may try to learn the the .sublime-build files in your Tools -> Build system -> New build system
So, you don't want to use an IDE but then you want IDE features from a text editor? :)
Most people who use a text editor for writing code use terminal to build and run the code.
So, for C++, the instructions are:
make (or gcc myprogram.c)
./myprogram
for a Python program, it's even simpler:
python ./myprogram.py
If you're not comfortable with terminal, then you probably need an IDE.
for c++ I actually made sublime to produce colorful error messages which are easier to read and you can also click on the errors which takes you to the file with the error.
You can look at how I modified the build to do what I wanted in here

Error in basic C++ program running in Netbeans IDE with Cygwin

I recently started learning C++ and I installed Netbeans IDE 6.9.1 and also the Cygwin compiler packages and configured them, and added Cygwin to my environment variable PATH like the instructions told me to.
I wrote a basic "Hello World" program and when I press Ctrl+F5 to "Debug Main Project" it seems to build fine but the black console/command prompt window flashes then disappears.
Then when I go to Run > Run Main Project, it builds and then a command prompt window pops up with the directory to "sh.exe" in its title.
I took a screenshot of the error message:
Does anyone know why this is happening and why I can't get the program to run properly even in debug?
Notice that in the screenshot I switched over to the MinGW tools because I thought maybe Cygwin was the problem, but the same error still occurs.
Any help would be greatly appreciated. Thank you.
"No such file or directory" in the error message is the key. When you run the project, it wants to access a file which is not there. Make sure that the paths are set up correctly.