Compile and execute?

So hi everyone, here is my problem…
When i writ the “g++” line to compile, do i need to press “Enter” to go underneath and type “./a.out” ?
Sorry if its a dumb question… Oh, and sory for my formidable english :slight_smile:

1 Like

Hi @course4327652278 - welcome to the forum! :slight_smile:

Not really. :slight_smile:

That would be one way to do it.

As you mention, to compile your C++ program you need to do something like g++ my_code.cpp and then hit Enter to have the compiler build your program. You’ll then get a new line in the terminal.

So, if we did compile on the first line, press Enter, then do the command to execute on the second line our terminal would look like this:

$ g++ my_code.cpp
$ ./a.out

or, because Bash is pretty nifty, you can do both commands on one line like so:

$ g++ my_code.cpp; ./a.out

That command gets bash to run the compiler (g++ my_code.cpp), before executing the resulting program (./a.out).

Does that help you? :slight_smile:

1 Like

Thanks alot, Its my first time learning c++

No worries. :slight_smile:

If you get stuck with anything else in the C++ course, pop back here to the forums and we’ll see if we can help out. :slight_smile:

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.