How to compile C++ program with g++



// file name hello_world.cpp
#include <iostream>
using namespace std;
int main()
{

   cout <<("Hello, World!");
   return 0;
}
This is basic code just print Hello World !. If you want to use GNU compiler then make sure its C++ Program then you have to use g++ or if its C Program then you have to use gcc.
 $ g++ hello_world.cpp -o hello 
This above code just compiles your code.It shows nothing in Terminal if you want to see the output you have to write this file is automatically appears on same folder
./hello
Just look code that you used to run, after -o we write hello that is why we use ./hello to see the output. If you forget to put -o .Then no worry,if you see the same folder where your code is then you will find a.out file. If you want to see output then use ./a.out 
Note- if you run second code without -o then this a.out will be overwritten with the latest version of the output.Its is good practics to use -o output_file_name.


Please comment if you have any suggestion and share to support us

😀 😄 😍 💗

0 Comments