here i copy form this web page:

http://www.learncpp.com/cpp-tutorial/713-command-line-arguments/

#include <iostream>

int main(int argc, char *argv[])
{
    using namespace std;

    cout << "There are " << argc << " arguments:" << endl;

    // Loop through each argument and print its number and value
    for (int nArg=0; nArg < argc; nArg++)
        cout << nArg << " " << argv[nArg] << endl;

    return 0;
}

where argc store the number of the arguments. it is at least 1, coz it contains the file name. when you type the argument, it will store in argv. in my case, i have a program for Fourier Transform called FFTW.mac

./FFTW.mac ise.dat 1000 abc

thus, ise.dat is the 1st argument, stored in argv[1], 1000 is 2nd, stored in argv[2], abc is 3rd, stored in argv[3]…etc.

Advertisements