In order to create a c++ file you need to write your code in an editor program like atom.

Once you write down your code you want to save your code as: name.cpp

That is super important: SAVE IT AS anyname.cpp << the .cpp is mega important for it to run.

And remember where you saved it. Remember in what folder you are saving it.

Now you have to go to a terminal (like cygwin in Windows, and Terminal in Mac) so you can run it. How do you do that?

First you have to change the directory you are now. How? you write: cd (which means change directory)

Example: cd c:

In this example it will change to your local disk c.

Once you are in the folder where you saved your program you want to write this:

g++ anyname.cpp << observe that first I wrote g++ for it to compile, then I wrote the name of my file including the .cpp

If your code has an error the program will tell you and you have to go and correct it, then come back and compile it again until it goes without any errors.

If it doesn´t have an error it won´t tell you anything. So you can run it now. In order for it to run you have to write:

./a.out << for everything except windows

./a.exe << for windows.

If it runs exactly what you wanted, you are done!

CC BY 4.0 Ability to create C++ file and run from command line by marinaruelas is licensed under a Creative Commons Attribution 4.0 International License.