Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File I/O in c++ and linux command line redirect

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.

like image 998
Max Avatar asked Dec 09 '25 14:12

Max


1 Answers

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).

like image 107
Oliver Charlesworth Avatar answered Dec 12 '25 04:12

Oliver Charlesworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!