0

I have already checked out the many similar questions on this website, but I keep getting this error when trying to run my program conversion.cpp with ./conversion.

The program is here:

(i can't seem to copy paste the text)

Whenever I run the program, I get the error that there is no such file or director. I have already tried chmod to no avail.

Any help would be great appreciated!

1 Answers1

3

You must compile your .cpp file into a binary file, chmod +x the resulting binary file, then run the compiled binary. You can do this easily with the following syntax:

g++ <cpp file> -o <resulting binary file>

i.e. the following for your particular program:

g++ conversion.cpp -o conversion

Example:

mgodby@mg-ws1:~/code$ g++ helloworld.cpp -o helloworld
mgodby@mg-ws1:~/code$ ls
helloworld  helloworld.cpp
mgodby@mg-ws1:~/code$ chmod +x helloworld
mgodby@mg-ws1:~/code$ ./helloworld 
Hello World!
mgodby@mg-ws1:~/code$

Note 1: If your compile fails for some reason, make sure that all necessary packages are installed -

sudo apt-get -y install g++

Note 2: You must re-compile, i.e. run the g++ command again, every time you make a change to the original .cpp file, else the changes you make will not take effect.


The reason that you cannot run your .cpp file directly is that c++ is a "compiled" language and not a "scripting" or "interpreted" language. If you'd like to know more about this particular distinction, you can refer to the following article to get the basics: Interpreted language - Wikipedia

MGodby
  • 1,172