Command Line Arguments in C++

Command line arguments are used to pass values to the program during execution. This code shows you how to implement that in C++

Source code :

#include<iostream>

using namespace std;

int main(int argc, char *argv[]){

cout<<"The Arguments are : "<<argv[1] <<" "<< argv[2]<<endl;

return 0;

}

Output :

The Arguments are : 1 2

Notes :

Compiling the program

g++ code.cpp

Executing the program

./a.out 1 2

Here 1 and 2 are commandline arguments.


Output :


                

Comments :