|
-
April 4th, 2009, 09:06 AM
#1
cout << EOF
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.
-
April 4th, 2009, 10:44 AM
#2
Re: cout << EOF
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;
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
April 4th, 2009, 01:17 PM
#3
Re: cout << EOF
Closing cout (fclose(cout)) will result in EOF being sent to the other end of the pipe.
-
April 4th, 2009, 01:34 PM
#4
Re: cout << EOF
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.
Last edited by tomas.srna; April 4th, 2009 at 01:37 PM.
-
April 4th, 2009, 02:03 PM
#5
Re: cout << EOF
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.
"A problem well stated is a problem half solved.” - Charles F. Kettering
-
April 4th, 2009, 02:25 PM
#6
Re: cout << EOF
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..
-
April 5th, 2009, 06:23 PM
#7
Re: cout << EOF
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).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|