I would like to embed code in a C ++ application running on Windows that can determine if stdout (or cout) points to the console, and if so, convert the characters to terminal encoding before writing them. If not (for example, when writing to a file or channel), the characters should be left alone. Part of the conversion is not a problem, but I wonder if it is even possible for the application to find out if its stdout goes to the console or to another place.
I am not sure if the GetStdHandle API Get function will be of any help, or if it simply means pointing to standard output, without being able to determine any information about it. Similarly, I'm not sure if there is any information we can get from cout that will indicate whether it points to the console or something else. Until now, I could not find anything in this direction.
source share