smashingpumpkin smashingpumpkin - 3 months ago 6
C Question

Command line argument like user input in c++

In command line argument like

./a.out echo *
the
*
will be changed by the terminal so that all the files in the directory can be printed. What I want is that standard input do the same thing.

Is there any way of doing this in C++? Any help will be thanked.

Answer

Please have a look at http://en.cppreference.com/w/cpp/language/main_function

you could write:

int main(int argc, char** argv)
{
  for(int i=0; i<argc; i++)
    printf("Element %d : '%s'\n", i, argv[i]);

  return 0;
}

Note: If you want to do this steps in C please have a look here Simple glob in C++ on unix system?