Hello,
Is it possible to send EOF to cout?
I am doing a test program "tester" and I need to send EOF signal, because I am using a pipe: "tester | tested" and "tested" waits for EOF.
However, when I use "cout << EOF", only -1 is sent to cout.
Thanks.
Printable View
Hello,
Is it possible to send EOF to cout?
I am doing a test program "tester" and I need to send EOF signal, because I am using a pipe: "tester | tested" and "tested" waits for EOF.
However, when I use "cout << EOF", only -1 is sent to cout.
Thanks.
This is a total guess. No idea if it'll work but it's got to be worth a try:-
Code:char eof = (char)0x1A;
cout << eof;
Closing cout (fclose(cout)) will result in EOF being sent to the other end of the pipe.
None helped..
0x1A is not EOF as I know, EOF is -1.
To the second reply: A nice idea, but at first try, compiler said that there are bad conversions, so I tried
fclose((FILE*)(void*)cout);
which sent EOF, but for the price of a segmentation fault afterwards..
Anyway, thanks for trying.
Take a look at this Wikipedia article and you'll find that EOF is a system dependent character, commonly (but not always) -1. AFAIK, Windows and DOS use Ctrl-Z to indicate EOF. This is equivalent to the ASCII character SUB (0x1A). You'll find some information about Ctrl-Z here.
I tried it, you are right :) But only in half.. SUB substitutes EOF in Windows, but not in Unix.. I have just tested it on both platforms.
Anyway, thanks! I didn't know about SUB character. At least it works on Windows.
Edit: Sorry.. You mentioned that it is only in Windows..
Oh, sorry! That was a stupid error. No, cout is of course a stream object, so you should be doing fclose(1) instead (1 being the usual identifier for stdout).