I think you make main() take two parameters; int argc and char** argv.
int main(int argc, char** argv) {
argv is an array of C-style strings of the command line parameters, with element 0 being the name used to call the executable. argv is the number of parameters.
In this code, argc is how many parameters are passed to your program, argv contains them. You treat argv as an array:
argv[0] - should contain the command used to execute the program (ie mycode.exe)
argv[1] - will be your first parameter (so hopeflly "mydata2.txt")
Then you need to do something like:
1 2 3 4 5 6 7 8 9
if(argc==2) // if there is a filename passed to it (only 1 extra parameter)
{
// all code goes here
ifstream myfile (argv[1]); // this is opening the file in the parameter
}
else // if 1 extra parameter was not passed
{
cout << "No file specified"; // tell the user they did not enter a file
}