ifstream help

Hey there C++ codies, I need some help again. I'm supposed to open a file that is provided by the user. Its supposed to be allowed to take a space if the user enters it, and I thought I solved it, but when i type check book.txt i get my error message prompt.

I can't seem to figure it out to save my life. So here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
	cout << "Enter a file name (including extension): " << endl;
	char FileName[300];
	cin.getline (FileName,300);
	ifstream input(FileName);

	if (!input.good())
	{
		cerr << "Unable to open file" << endl;
		exit(1);
	}
	


It compiles fine, and I don't get any error messages. Thoughts?
maybe your file doesn't exist. Program works for me.


C:\Temp>testxxx5
Enter a file name (including extension):
out 1.txt
out 1.txt
C:\Temp>testxxx5
Enter a file name (including extension):
no such file.txt
Unable to open file

C:\Temp>testxxx5
Enter a file name (including extension):
nofile.txt
Unable to open file

C:\Temp>
Last edited on
Topic archived. No new replies allowed.