I have several arguments to my program and an input file being redirected. i am parsing the arguments (using argc and argv) and the file (using cin). However, I am not able to display the name of the redirected file. For instance, the arguments are-
./procsim -r 2 -f 4 -j 3 -k 2 -l 1 < gcc.100k.trace
and my code to parse the arguments is -
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
{
if (!strcmp(argv[i], "-r"))
{
if (i < argc - 1)
{
pipeline_parameters[count++] = atoi(argv[i+1]);
R = atoi(argv[i+1]);
i = i+1;
}
}
else if (!strcmp(argv[i], "-f"))
{
if (i < argc - 1)
{
pipeline_parameters[count++] = atoi(argv[i+1]);
F = atoi(argv[i+1]);
i = i+1;
}
}
and to parse the file, I use cin -
string line;
while (getline( cin, line))
{
address_arr.push_back(line);
}
I want to read the fie name, which is gcc.100k.trace here. how do i do that? P.S. - I have tried parsing through the arguments, but I'm not able to find it!
Edit: address_arr is a vector of int. pipeline_parameters is an array of int of length 5, to store the arguments. R and F are global variables which store the arguments as well.
stdin. Take a look at this answer to another SO post. It may lead you to find an answer to your question.