0

For some reason the code is not printing the error string in the output screen of the operating system. Go figure? This code is directly out of the book.

#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

ofstream fileout;
ifstream filein;

void main()
{
	char file[20];		//you must type in filename and extension
	char inChar;

	cout << "What is the name of the file you want to see? ";
	cin >> file;
	filein.open(file, ios::in);
	if(!filein)
	{	
	         cout<<"\n\n*** That file does not exist ***\n";	//not displaying for some reason
		exit(0);
	}	while(filein.get(inChar))
	{
		cout << inChar;
	}
	filein.close();
	return;
}

<< moderator edit: added [code][/code] tags >>

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by Catweazle
0

It sounds like the stream isn't getting flushed. That's not correct behavior because calling exit() will flush all output streams with unwritten data. Just for grins, try changing cout to cerr and see what happens. cerr has the unitbuf flag set by default, so it should flush the stream after every operation. If that works then the compiler isn't predictable enough to be useful and you should get a newer version. Visual C++ 2005 Express Beta 2 is free for download, and conforms to the C++ standard very well. Dev-C++ is also a good conforming compiler, but the IDE is lacking in my opinion.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.