How do you go down in the terminal?

I’m trying to code in C++, but when I need to compile and execute, I need to return a line. To return, as far as I know, you press enter, but enter only causes the program to execute my unfinished code. This isn’t a big deal, its just a minor annoyance.

Hi @kearkelk

I’m struggling to understand what you’re doing, tbh.

If you’re working through the Codecademy C++ material, “compile” and “execute” are two different actions in the learning environment. You compile with g++ my_code.cpp and execute it with ./a.out for example.

These would already be two separate commands* to the terminal, so it would (assuming no errors) look like:

$ g++ my_code.cpp
$ ./a.out
some output from your code is here!

If that’s not what you’re talking about, then I’m genuinely confused. Unless you can elaborate a bit more about what you’re doing and how, with a screenshot maybe, I’m lost. :frowning:

* Unless you’re familiar enough with bash to know you could do $ g++ my_code.cpp; ./a.out for the same result.

Sorry for not being clear enough, I know what the commands are, and how execute and compile work, it’s just that I need to go down a line in the bash terminal and I don’t know how.

Go down? Start a new line? Should the program do that, or you?
When does a terminal display a new line? It’s not an action to be carried out, it’s a character in the output stream, so if your program should terminate a line, then it would need to write a line termination character.

Might make more sense if you don’t think of your program as having control over your terminal, instead it simply writes characters that you can direct into a file or into a terminal application or a network connection or be ignored altogether.

1 Like

How did you go down from your g++ my_code.cpp to the ./a.out without pressing enter… everytime I press enter to go down to the second line of the terminal… it executes the command making it incorrect

Hello, @connercandiloro43440, and welcome to the forums.

g++ my_code.cpp



are separate commands. They should be executed separately. The first one compiles your code, and creates an executable file named a.out by default. The next command ./a.out executes the executable file created by the compiler. If you are getting an error message when clicking <enter> after typing g++ my_code.cpp then you have an error in your code that is preventing it from being compiled. The error message should give you a pretty good clue as to what the error is.