You can use command line arguments. But your main should look like as below.
Where argc shows the argument count (including the executable itself) and argv shows the arguments (including the name of the executable itself). So argc = 1, argv = {"myProgram"} by default. (if your output file is "myProgram")
int main (int argc, char* argv[])
{
fstream file;
if (argc == 2){
file.open(argv[1],ios::in);
}else{
// handle the error
}
}
When you run the program :
./myProgram "/filepath"
But make sure to check argc, before using argv[1], to avoid segmentation faults, when there are no additional arguments given.