Reputation: 763
I’m trying to run my c++ files off the prompt, but nothing is showing, e.g.
C:\C++\mingw>g++ hello.cpp -o hello.exe
It seems to be bug free but nothing displays, in this case a simple hello to the terminal.
My code is a straightforward
#include <iostream>
using namespace std;
int main()
{
cout << "Hello \n" << endl;
return 0;
}
Upvotes: 2
Views: 5977
Reputation: 39370
Of course, the simplest answer "Just run hello.exe
" is correct. Here's some additional logic behind:
If you're used to interpreted languages, such as Python or Lua, you might have noticed that you execute them by supplying source file to the executable, as such:
python my_source.py
However, this works because each time you run python
command, it reads the source file given, and then interprets it and executes appropriate machine instructions based on the file contents - it interprets the file.
C++, on the other hand, is a compiled language. The execution of g++
, which is a compiler, generates said machine code for your platform, and stops there. Next time you don't need the compiler to run your program; every instruction is encoded as the machine code in the .exe
file. That's why you can share your .exe
file with your friend if he doesn't have a compiler, but he won't be able to execute python script without python environment installed.
Upvotes: 4
Reputation: 1157
g++ hello.cpp -o hello.exe // This command only produce the exe file
The executive file doesn't run automatically. You should run it by yourself.
hello.exe
Upvotes: 2