Thread: eofbit with standard input stream

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    242

    eofbit with standard input stream

    In the last chapter of Prata, C++ Primer Plus, p. 1001, he has the following code:

    Code:
    while(cin.peek() != '#')
    	{
    		cin.get(c);
    		cout << c;
    	}
    	if (!cin.eof())
    	{
    		cin.get(c);
    		cout << endl << c << " is next input character.\n";
    	}
    	else
    		cout << "End of file reached.\n";
    when would it be the case that with the usual keyboard input, eofbit is set? The fact that he writes the code this way suggests that it can happen... ?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is possible to simulate EOF, e.g., CTRL + D, or CTRL + Z, as the case may be.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    242
    ah, so that's it: ctrl + d for unix, ctrl + z for windows?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with input stream
    By cbalu in forum C Programming
    Replies: 8
    Last Post: 05-18-2010, 11:30 AM
  2. How to declare a global input stream
    By Chazij in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2008, 04:53 PM
  3. Help loading a vector with input from input stream
    By Bnchs in forum C++ Programming
    Replies: 9
    Last Post: 11-07-2006, 03:53 PM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  5. Buffering??
    By Brain Cell in forum C Programming
    Replies: 15
    Last Post: 09-21-2004, 06:57 AM