Thread: "end of file" in Windows

  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715

    "end of file" in Windows

    Hi, I've been reading B. Stroustrup's FAQ and found
    How do I write this very simple program?

    What is interesting is this sentece:
    The program ends reading input when it sees "end of file". If you run the program from the keybord on a Unix machine "end of file" is Ctrl-D. If you are on a Windows machine that because of a bug doesn't recognize an end-of-file character, you might prefer this slightly more complicated version of the program that terminates input with the word "end":
    I test it on my Dev-Cpp compiler with this code
    Code:
            #include<iostream>
    	#include<vector>
    	#include<algorithm>
    	using namespace std;
    
    	int main()
    	{
    		vector<double> v;
    
    		double d;
    		while(cin>>d) v.push_back(d);	// read elements
    		if (!cin.eof()) {		// check if input failed
    			cerr << "format error\n";
    			return 1;	// error return
    		}
    		if(cin.eof())
    		{
                         cout<<endl<<"Test is OK"<<endl;
                    }
    
    		cout << "read " << v.size() << " elements\n";
    
    		reverse(v.begin(),v.end());
    		cout << "elements in reverse order:\n";
    		for (int i = 0; i<v.size(); ++i) cout << v[i] << '\n';
    
    		return 0; // success return
    	}
    And after entering Ctrl-Z I saw line "Test is OK".
    Can you comment this?
    I'd like to read your opinion on this.

    Cheers!

    Micko
    Last edited by Micko; 04-03-2005 at 02:05 AM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There have been a large number of different compilers for windows machines, some of which are less buggy than others.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Quote Originally Posted by Salem
    There have been a large number of different compilers for windows machines, some of which are less buggy than others.
    Ok, so under Windows Ctrl-Z means end of file and I can assume this when working with MSVC++ .net and Dev-Cpp?
    Last edited by Micko; 04-03-2005 at 03:45 AM.
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Ok, thanks Salem, always very reliable!
    Gotta love the "please fix this for me, but I'm not going to tell you which functions we're allowed to use" posts.
    It's like teaching people to walk by first breaking their legs - muppet teachers! - Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:16 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM