Sum the two numeric command line arguments : command line arguments « Development « C++ Tutorial






#include <iostream> 
#include <cstdlib> 
using namespace std; 
 
int main(int argc, char *argv[]) 
{ 
  double a, b; 
 
  if(argc!=3) { 
    cout << "Usage: main num num\n"; 
    return 1; 
  } 
 
  a = atof(argv[1]); // convert first command-line arg 
  b = atof(argv[2]); // convert second comnand-line arg 
 
  cout << a + b; 
 
  return 0; 
}
Usage: main num num








5.11.command line arguments
5.11.1.Display command-line arguments
5.11.2.Using command-line arguments for copying files
5.11.3.Sum the two numeric command line arguments