I am able to generate the output file but it does not execute.

This is what I do:

g++ program.cpp -o program

then I can see the program as the output file but when I type program it says:

It says bash: program: command not found.

So, what am I missing?

Thank you for your time.

Hello

Why not compile with DevC++ and then just run the exe file?
To run the file in cmd, just go to the directory where it's located and type the exe's name. Without the extension. Or I guess you could type that too, but I rarely use it.

Try, at the command prompt enter:
./program <enter>

Yup, sounds like the folder you are working in is not on your PATH. You can either use ./program, or you can add the working directory to your PATH by putting this in your ~/.bashrc file:

export PATH=$PATH:/home/youruser/where_you_are_working

Yeah, it seems the path variable doesn't point to "." (a current directory). You may add to your ~/.bashrc something like PATH=$PATH:., or just add the explicit path of your output directory.

Adding . to your path is an original security risk that isn't worth repeating.

Joe Hacker puts a file called 'ls' in some directory and just waits for you to come along....

Adding . to your path is an original security risk that isn't worth repeating.

Joe Hacker puts a file called 'ls' in some directory and just waits for you to come along....

Well, that's not the exact definition of the problem, since JH would better put his trojan on the first directory of the $PATH, once he managed to get in. IMHO, a probability of inconsistent (let's say dependent on the $PWD) behaviour could be some risky.

I imagine that the answer to the OP's question is what Ancient Dragon somehow accidentally posted in post 1:

Hello

Why not compile with DevC++ and then just run the exe file?
To run the file in cmd, just go to the directory where it's located and type the exe's name. Without the extension. Or I guess you could type that too, but I rarely use it.

Try, at the command prompt enter:
./program <enter>

Since the error says "bash", presumably the OS is Linux, so do what is in red. The black part would be advice for Windows.

And, BTW, you're quite safe, if "." is the last directory of your $PATH; the shell will obviously scan all the "legal" directories first. Eventually, "GNU ls" will remain the leader for invocation, even if your hypothetical JH puts his "wrong ls" in $PWD.
Regards

Assuming you can always spell correctly?
Ever type 'sl' instead?
It isn't safe anywhere in your path.

Assuming you can always spell correctly?
Ever type 'sl' instead?
It isn't safe anywhere in your path.

Mistyping is obviously risky ;-), but if I was an imposter I'd still better put my "sl" trojan into "/usr/local/bin" to be sure that each invocation of "sl" succeeds. I frankly cannot figure out the situation, when using "." at the very end of the $PATH is significantly riskier than the explicit call.
Regards

This article has been dead for over six months. Start a new discussion instead.