samedi 29 octobre 2016

How to know when there is input through the terminal pipe line on C++ 11?

How to know when there is input through the terminal pipe line on C++ 11?

I may call my program like this:

  1. ./main.o solved.txt
  2. cat unsolved.txt | ./main.o
  3. cat unsolved.txt | ./main.o solved.txt

I am using this to know whether I need to read data from the pipe line or not on C++ POSIX Standard:

// If it is passed input through the terminal pipe line, get it.
if( !isatty( fileno( stdin ) ) )
{
    // Converts the std::fstream "std::cin" to std::stringstream which natively supports
    // conversion to string.
    inputedPipeLineString << std::cin.rdbuf();

    printf( "inputedPipeLineString: %s", inputedPipeLineString.str() );
}

But now I want to use the C++ 11 Standard, and my loved fileno and isatty are out of it. So there is an alternative to them on the C++ 11?

Aucun commentaire:

Enregistrer un commentaire