C++ compile and execute

I don’t understand how to use the compile and execute commands. When ever I type the commands down they don’t do what they are supposed to. I just started c++ last night.

Hey there and welcome to the forums! :slightly_smiling_face:

What commands are you using and what’s your file named? Assuming I have a file name main.cpp the command to compile would be g++ main.cpp. This would produce a file named a.out which we can execute with ./a.out.

1 Like

Thank you for the reply, I have tried this and it does not produce a new file.

Are you typing the command in the terminal, or adding it to the code in the editor? If you aren’t sure, post a screen shot.

1 Like

I am typing it too the code in the editor

You have to type the command in the terminal, and then hit enter.

What you write in the editor is editing a file. When you enter the commands in the terminal you are telling the computer to compile that file, and then telling it to execute the outputted file.

1 Like

Thank you so much for the help

Credit were credit’s due. @midlindner saw the issue first :smile:

1 Like

Code is a list of instructions for the computer to follow. If you wrote a recipe for cookies, and the last line was, “Make the cookies”, would they just appear? Not likely. You would have to instruct someone to follow the recipe, and make the cookies.

The computer has to be told outside of the list of instructions to compile and execute the instructions. As @8-bit-gaming said, that happens in the terminal.

1 Like

You’d have seen it, had I not chimed in.

1 Like