How can we know the name of the stream to which output is being redirected through a C++ program?
For example, I have a program 1.cpp whose output is being redirected to a file a.txt
i.e., a.out > a.txt
Now, I want to know the name of the file to which output is being redirected in the program itself.
How can I do that?

Thanks in advance.

No. Redirection, piping and general screen printing are facilities of the OS, not your program. Additionally, there are other tools, such as tee which would complicate the matter if you could. Suppose you had ./a.out | tee a.txt would you want that tee was receiving your output or that it was ultimately sent to a.txt?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.