Create and run C++ file

Although sometimes it seems a bit complex, it’s actually very easy to compile and run a program, let’s go step by step.

On the first screenshot we can see the directory we need to follow on cygwin, it’s not the same for every folder, that means you need to change it to wherever your source code is saved.

It always needs to start with cd /cygdrive/…… and then as you can see mine has a few directions.

Also to type in a basic program your code must start with

<iostream>

using namespace std;

int main()

and you start typing your code

I just typed in a “Hello from Mexico with Love” as an example, once your done with your code you need to save like this “whatevernameyouwant.cpp” be sure to type in the .cpp so that the compiler (cygwin) can know that we have a C++ file.

Then to compile it on cygwin you type the g++ command and the name of your program with .cpp at the end.

After that you type in an “ls” command to check your programs on that folder.

And to finish you just need to run in with ./a.exe

The screenshot shows every command, I hope it helps.

CC BY 4.0 Create and run C++ file by Salvador García is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.