CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: cout << EOF

  1. #1
    Join Date
    Nov 2007
    Posts
    4

    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.

  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  3. #3
    Join Date
    Dec 2005
    Location
    England
    Posts
    86

    Re: cout << EOF

    Closing cout (fclose(cout)) will result in EOF being sent to the other end of the pipe.

  4. #4
    Join Date
    Nov 2007
    Posts
    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.

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    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

  6. #6
    Join Date
    Nov 2007
    Posts
    4

    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..

  7. #7
    Join Date
    Dec 2005
    Location
    England
    Posts
    86

    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
  •  





Click Here to Expand Forum to Full Width

Featured