Thread: i need up with end of file

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

    i need up with end of file

    hey in my book it talks about end of file in c++ i think its where u would make ctrl+q for example end the program and stuff like that and i have no idea how it works so if anyone cna help me id appreciate it thanx

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    the end of file is a flag that literally marks the end of a file. YOu could use it while reading a file

    so

    while(!=EOF)
    read file

    you dont have to define it as when the data in a file ends there is an eof flag - i think its marked by a -1 value but im not 100% sure on that
    Monday - what a way to spend a seventh of your life

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    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
    hooch

  4. #4
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    there are no references to eof in that code, it uses cin.fail() - im not quite sure what this does - its something do with the data stream being checked for 'bad' values - i dont know if EOF is included in that.
    Monday - what a way to spend a seventh of your life

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    well eof is end of file right? and the book is talking about it the book is called c++ primer plus if uve heard of it or have it . its on page 191-193 sumthin like that
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  4. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 08:26 PM
  5. checking for end of file
    By linucksrox in forum C Programming
    Replies: 7
    Last Post: 06-01-2004, 01:41 AM