how does this program work

This is a discussion on how does this program work within the C++ Programming forums, part of the General Programming Boards category; well how would EOF work in this code? #include <iostream.h> int main() { char ch; int count = 0; cin.get(ch); ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    how does this program work

    well how would EOF work in this code?



    #include <iostream.h>
    int main()
    {
    char ch;
    int count = 0;
    cin.get(ch);
    while (cin.fail() == false)
    {
    cout<<ch;
    count++;
    cin.get(ch);
    }
    cout<<"\n"<<count<<"characters read\n";
    return 0;

    }

    how does taht get the output of

    u type in anything u want
    it repeats itself once
    keeps this apttern up till u hit ctrl+z

    how does that work


    im more curious tho how does the program no how to terminate at ctrl+z
    hooch

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    EOF has nothing to do with that code. When you type Ctrl+Z that causes cin.fail() to return true.
    That will exit your while loop.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    how does the program kno to terminate with ctrl+z how does cin.fail() know that or is that jus a command by default for cin.fail?
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. threaded program doesn't work?
    By OcTO_VIII in forum Linux Programming
    Replies: 1
    Last Post: 12-11-2003, 11:37 AM
  4. The Bludstayne Open Works License
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-26-2003, 10:05 AM
  5. Can't get program to work
    By theirishrover12 in forum C Programming
    Replies: 1
    Last Post: 06-08-2002, 11:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21