I want to be able to write a line in a terminal (as below) that takes a text file in the same directory and inputs its name into an executable file.
cat fileName | executable
I want to be able to read the fileName into c++ code. I already have a code that accesses the lines and reads through the file, it is just receiving fileName from the standard input.
Is there a line of code or a function to read the fileName into a c++ program and store it as a string? I am currently using the below code to read through each line of the text file.
ifstream myfile;
myfile.open(fileName.c_str());
if( myfile.is_open() )
{
while ( getline (myfile ,line) )
{
......
}
}
|
pipes the data../myprog *.c
). Some programs do have an option to read filenames from stdin, for use withfind ... | myprog
, but you can alwaysfind ... -exec myprog {} +
, now that find has the+
feature for exec. There's always... | xargs -d'\n' myprog
.