title: How to I add command-line arguments in a C++ program?
body: <p>I am just learning about command line arguments in my class and I do not fully understand them yet. I understand that they are stored in *argv[], and are counted by argc, but I do not understand their purpose or where they come from. I have attempted to write a program in C ++ to find the sum of command line arguments input by a user and have included the code below, but I have no idea if it is correct or how I would even test it. If someone could give me a simple description of what they are and how to access them it would be greatly appreciated.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  int main(int argc, char *argv[])
  {
      double sum = 0;
      for(int counter = 0; counter &lt; argc; counter ++)
      {
          sum += atof(argv[counter]); //compact form of :  sum = sum + atof(argv[counter]);
      }
      cout &lt;&lt; "Sum = " &lt;&lt; sum &lt;&lt; endl;
  }
  </code></pre>