3

I've got a program that accepts a text file with a map on it, then finds the shortest path and outputs that to another file.

it needs to work like this

./pathFinder -arg < inputMap.txt > outputMap.txt

My question is, with this input, what would get filled into argv[] and argc (do the redirects count as arguments), and also should I use file streams or just cin/cout... or maybe something else. Thanks.

4
  • I just tried using cin and the program waits for input instead of using the txt file. Commented Sep 22, 2011 at 1:03
  • cin and cout are a "file streams". Commented Sep 22, 2011 at 1:04
  • Sorry, I meant ifstream and ofstream Commented Sep 22, 2011 at 1:04
  • @Max - if your program waits for input, then either you aren't invoking as you describe, or your program has a bug. Please reduce your program to the smallest version that still exhibits the problem, and post that here. For comparison, see this program. Commented Sep 22, 2011 at 1:56

3 Answers 3

3

argc will be 2, and argv[1] will point to "-arg".

Redirects will simply appear on stdin and stdout (wrapped by std::cin and std::cout).

Sign up to request clarification or add additional context in comments.

7 Comments

@quasiverse: No. This is handled by the shell.
cin>>var hangs for keyboard input, is there a different way if you are expecting input from a file?
@Max: I'm not sure I understand what you mean. The shell literally streams in the content of the file instead of the characters you type at the console.
@Max If you redirect it and it still hangs then the file doesn't have the correct input or you're doing it wrong.
Thanks for the help thus far... When I run the program, it behaves the same way whether I include the redirects or not. (waits for input)
|
2

argv will contain {"./pathFinder", "-arg"}

1 Comment

@Kerrek: Thanks. I should have just used copy/paste.
0

The redirect will not count as arguments. Just use cin/cout will be fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.