0

I have a program that needs to open a file, parse it line by line, and run some code with those lines. I have the program doing what I want except that it has to prompt for the target file. I need it to get that file from a makefile instead.

The makefile line is:

$(PATH)/program.exe file.txt

What I'm not sure how to do is open file.txt in program.exe. The only way I know to open files in c++ is:

ifsream file;
file.open(some_string_here)

Should I be using something like this: c-comm-line-strings? Just call argv, or is there a better way to do this?

Edit for question clarity: The question I have here is "How do I actually use the command line arguments?" Answer supplied in comments by R Sahu

Community
  • 1
  • 1
Eric
  • 452
  • 1
  • 5
  • 18

1 Answers1

0

(I think I know the answer, but I work in UNIX and you seem to be using Windows, so some of what follows may need some adjustment.)

If I'm reading your question right, you can execute your program on the command line:

./program.exe

it prompts you for a filename, you give it "file.txt" and everything runs smoothly. Try passing the input through a pipe:

echo file.txt | ./program.exe

If that works, you can put it in your makefile:

echo file.txt | $(PATH)/program.exe
Beta
  • 96,650
  • 16
  • 149
  • 150
  • Thank you for the info, but my question was actually, how do I use the command line argument. R Sahu said that the link I asked about would work for what I needed. – Eric Jun 01 '15 at 14:39
  • @eric: Ah, so the question actually has nothing to do with Make, or opening a text file. – Beta Jun 01 '15 at 14:44