kkooty
asked on
file redirection
how do we read in a data file using redirection sign ie < so that we are able to pass the data in and use in the program. we want to be able to type
a.out < filename where a.out is the executable and filename is the text file
with data in it.
a.out < filename where a.out is the executable and filename is the text file
with data in it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks that was usefull.
If you are "done" then you should grade the question. If not, no rush.
Executing command
type filename | a.out
will pass text found in file "filename" to the standard input stream (like scanf or cin) of executable a.out
type filename | a.out
will pass text found in file "filename" to the standard input stream (like scanf or cin) of executable a.out
You can read text from the input stream object using the getline() member function, but this is inconvenient if you don't know the length of the line to be read (you have to set an arbitaray limit.) so I prefer to use the global getline function which reads a line of any length into a string object, like
string CurLin
getline(cin,CurLin); // read a line.
let me know if you have any questions.