Let's look at how to save the file, compile and run the program.
Please follow the steps given below:
- Open a text editor and add the code as above.
- Save the file as: hello.cpp
- Open a command prompt and go to the directory where you saved the file.
- Type 'g++ hello.cpp' and press enter to compile your code. If there are no errors in your code the command prompt will take you to the next line and would generate a.out executable file.
- Now, type 'a.out' to run your program.
- You will be able to see ' Hello World ' printed on the window
$ ./a.out
HelloWorld
- Make sure that g++ is in your path and that you are running it in the directory containing file hello.cpp
0 on: "Compile & Execute C++ Program"